Skip to main content
XenonStack

Big Data Engineering

XenonStack Blog Apache Spark Architecture Explained Simply

and | Published | Updated

Apache Spark Architecture Explained Simply
9:41

Key takeaway

  • Apache Spark architecture explained: driver, executors, cluster managers, how a job runs, Adaptive Query Execution, when not to use Spark and agent impact.

Apache Spark architecture is a driver and executor model: a driver process turns your code into a plan and schedules tasks, a cluster manager allocates resources, and executors on worker nodes run the tasks in parallel and hold data in memory or on disk. Each application runs as its own independent set of processes.

This guide is for data engineers, platform owners and architects who need to understand how Spark runs a job, which cluster manager to pick, what makes jobs fast or slow, and when another tool is the better choice. It follows the official Spark cluster mode overview and performance tuning guide.

What are the core components of Spark architecture?

The cluster mode overview says Spark applications "run as independent sets of processes on a cluster, coordinated by the SparkContext object in your main program (called the driver program)". Four building blocks appear in every deployment.

ComponentWhat it doesArchitectural note
Driver programRuns your main function, builds the plan and schedules tasksShould run close to the worker nodes, preferably on the same local network, and must be network addressable from them
SparkContext and SparkSessionConnect to the cluster manager, acquire executors, send code and tasksSparkSession is the usual entry point for DataFrame and SQL work
Cluster managerAllocates resources across applicationsStandalone, Hadoop YARN or Kubernetes
ExecutorsProcesses on worker nodes that run tasks and keep data in memory or disk storageEach application has its own executors for its whole lifetime

That design isolates applications on both the scheduling side and the executor side, because tasks from different applications run in different JVMs. The cost, in the documentation's words, is that "data cannot be shared across different Spark applications without writing it to an external storage system". Plan a storage layer for sharing results.

How does a Spark job run?

Spark separates describing work from doing it. Transformations such as filter or join are lazy and only record what should happen. An action such as a count or a write triggers execution.

Two-column diagram of Spark: driver side with driver program, plan, stages and tasks; cluster side with cluster manager, executors, isolation and external storage.
  1. Submit. The application starts from spark-submit, a notebook or another client, and the driver connects to the cluster manager.
  2. Acquire executors. Executors start on worker nodes and stay up for the whole application.
  3. Plan. DataFrame and SQL code becomes a plan that the optimiser rewrites before execution.
  4. Split into stages. Each action creates a job, divided into stages at shuffle boundaries. A shuffle redistributes data across partitions and is usually the costliest step.
  5. Run tasks. Each stage runs as tasks, one per partition, sent to executors.
  6. Return or write results. Production jobs usually write to storage.

For architects, the number and size of shuffles often matters more to run time and cost than raw data volume.

Which cluster manager should you choose?

The cluster overview lists three cluster managers. Older guides also describe Apache Mesos, but it does not appear in the current list, so check your version before relying on it.

Cluster managerHow the documentation describes itBest fit
Standalone"A simple cluster manager included with Spark that makes it easy to set up a cluster"Dedicated Spark clusters, simple set-ups and testing
Hadoop YARN"The resource manager in Hadoop 3"Existing Hadoop estates with HDFS and YARN capacity
Kubernetes"An open-source system for automating deployment, scaling, and management of containerized applications"Container-first platforms and mixed workloads

Spark is agnostic to the manager: as long as it can acquire executor processes and they can communicate, it runs on a manager that also supports other applications. Choose by where your platform team already operates capacity. Our guide to Apache Hadoop explains the HDFS and YARN layer many estates still run.

How does Spark optimise performance?

Spark SQL uses an optimiser to plan DataFrame and SQL work, which is a reason to prefer those APIs over low-level RDD code. On top of that, the performance tuning guide describes Adaptive Query Execution (AQE), which "re-optimizes the query plan in the middle of query execution, based on accurate runtime statistics" and has been on by default since Spark 3.2.0.

AQE featureWhat it doesWhy it helps
Coalescing post-shuffle partitionsMerges contiguous shuffle partitions using runtime statisticsYou do not need to pick a precise shuffle partition count
Join strategy switchingConverts a sort-merge join to a broadcast hash join when one side is small at run timeAvoids a large shuffle
Skew join handlingSplits skewed partitions into roughly even tasksStops one oversized task holding up a stage

Other levers are covered in our Apache Spark optimisation techniques guide: fewer and smaller shuffles, caching only reused data, and sensible table layout. For deployment on a public cloud, see Apache Spark on AWS.

How does Spark handle streaming and lakehouse workloads?

Structured Streaming lets you write a streaming query like a batch query on the same SQL engine. For the messaging side of these designs, see real-time event processing with Kafka. In many new platforms Spark is the compute layer and an open table format such as Delta Lake or Apache Iceberg is the storage contract, so several engines can read the same governed tables. Confirm feature support for your Spark version and table format on their documentation before committing.

When is Spark the wrong tool?

Spark pays a coordination cost: a driver, executors, a cluster manager and network shuffles. That cost is worth it when data or compute will not fit on one machine, or when you need distributed streaming. It is often not worth it when:

  • The data fits on a single server, where an in-process engine such as DuckDB may be simpler.
  • Queries are small and interactive, so cluster start-up dominates run time.
  • The workload is transactional, with many small reads and writes by key.
  • The team needs a plain SQL warehouse rather than a programmable engine.

Our overview of open-source big data tools compares the wider landscape.

How do AI agents change Spark architecture decisions?

Agents need fresh, governed data and a record of what they acted on. Spark often prepares that data: feature engineering, joins and streaming enrichment. The architectural questions become which tables agents may read, how lineage is kept across jobs, and how a decision is traced back to its inputs. ElixirData, XenonStack's Context OS, keeps governed context and policy together above the data platform. Our real-time data analytics services help design that platform.

What should you do first?

  1. Find where RDD code and low-level APIs remain.
  2. Decide which cluster manager your platform team will run long term.
  3. Review the largest jobs for avoidable shuffles.
  4. Choose the table format that will be your storage contract.
  5. Name one agent decision that depends on a Spark-produced table and check its lineage.

To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What are the main parts of Spark architecture?

A driver program with a SparkContext or SparkSession, a cluster manager, and executors on worker nodes. The driver plans and schedules, and executors run tasks and keep data in memory or on disk.

Which cluster managers does Spark support?

The current cluster mode overview lists Standalone, Hadoop YARN and Kubernetes.

Can two Spark applications share data directly?

No. Each application has its own executors, so data cannot be shared between applications without writing it to an external storage system.

Is Adaptive Query Execution on by default?

Yes, since Spark 3.2.0. It coalesces shuffle partitions, switches join strategies and handles skewed joins at run time.

What is the difference between a job, a stage and a task?

An action creates a job. The job is split into stages at shuffle boundaries, and each stage runs as tasks, one per partition.

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue