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.
| Component | What it does | Architectural note |
|---|---|---|
| Driver program | Runs your main function, builds the plan and schedules tasks | Should run close to the worker nodes, preferably on the same local network, and must be network addressable from them |
| SparkContext and SparkSession | Connect to the cluster manager, acquire executors, send code and tasks | SparkSession is the usual entry point for DataFrame and SQL work |
| Cluster manager | Allocates resources across applications | Standalone, Hadoop YARN or Kubernetes |
| Executors | Processes on worker nodes that run tasks and keep data in memory or disk storage | Each 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.
- Submit. The application starts from spark-submit, a notebook or another client, and the driver connects to the cluster manager.
- Acquire executors. Executors start on worker nodes and stay up for the whole application.
- Plan. DataFrame and SQL code becomes a plan that the optimiser rewrites before execution.
- 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.
- Run tasks. Each stage runs as tasks, one per partition, sent to executors.
- 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 manager | How the documentation describes it | Best 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 feature | What it does | Why it helps |
|---|---|---|
| Coalescing post-shuffle partitions | Merges contiguous shuffle partitions using runtime statistics | You do not need to pick a precise shuffle partition count |
| Join strategy switching | Converts a sort-merge join to a broadcast hash join when one side is small at run time | Avoids a large shuffle |
| Skew join handling | Splits skewed partitions into roughly even tasks | Stops 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?
- Find where RDD code and low-level APIs remain.
- Decide which cluster manager your platform team will run long term.
- Review the largest jobs for avoidable shuffles.
- Choose the table format that will be your storage contract.
- 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.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE