Apache Spark Architecture (Driver, Executors, Cluster Manager, DAG Scheduler)
Map the driver, executors, cluster managers, and DAG scheduler that execute your Spark application.
In plain words
Driver starts and requests executor resources. Next, catalyst builds a physical DAG and stages. Finally, task reports, shuffle blocks, retries, and final output.
Think of it like…
The driver is a construction foreman with the DAG blueprint; executors are crews with tools and lumber, while the cluster manager grants each crew its fenced work area.
Where you’ve seen it
spark.sql.shuffle.partitions=800 is not automatically correct: a 10 TB join may need enough tasks, but 800 one-row partitions waste scheduler work; size partitions from bytes and task time rather than a copied default.
Words you’ll hear
- Driver
- The application JVM/Python controller that owns the SparkContext, plan, scheduler state, and result collection.
- Executors
- Long-lived JVM processes that run tasks, store shuffle/cache blocks, and are replaced after failures by the cluster manager.
- DAG Scheduler
- The scheduler that translates a logical execution graph into jobs, shuffle stages, and partition-level tasks.
- Operational boundary
- Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead. Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs.
Visual diagram
Theory & deep dive
Driver: the working mechanism
A Spark driver creates a logical plan, schedules a DAG through a cluster manager, and dispatches serializable task closures to executors that run partitions and report shuffle/execution state.
Driver starts and requests executor resources. Catalyst builds a physical DAG and stages, then tasks map to executor cores and partitions; this exposes the state governed by DAG Scheduler.
spark.sql.shuffle.partitions=800 is not automatically correct: a 10 TB join may need enough tasks, but 800 one-row partitions waste scheduler work; size partitions from bytes and task time rather than a copied default.
Apache Spark Architecture: failure mode and production response
Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs. Track Executor cores as "often 2–5 to balance parallelism, I/O, and GC", and make Executor memory visible to the dataset owner.
How it works, step by step
Step 1 of 41. Submit
Driver starts and requests executor resources. A Spark driver creates a logical plan, schedules a DAG through a cluster manager, and dispatches serializable task closures to executors that run partitions and report shuffle/execution state.
- Executor cores
- often 2–5 to balance parallelism, I/O, and GC
- Executors
- Long-lived JVM processes that run tasks, store shuffle/cache blocks, and are replaced after failures by the cluster manager.
When to use it & trade-offs
What it is
A Spark driver creates a logical plan, schedules a DAG through a cluster manager, and dispatches serializable task closures to executors that run partitions and report shuffle/execution state. spark.sql.shuffle.partitions=800 is not automatically correct: a 10 TB join may need enough tasks, but 800 one-row partitions waste scheduler work; size partitions from bytes and task time rather than a copied default.
Why it matters: Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead. Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs.
When to reach for it
- Map the driver, executors, cluster managers, and DAG scheduler that execute your Spark application.
- Choose Driver because it provides this capability: The application JVM/Python controller that owns the SparkContext, plan, scheduler state, and result collection.
- Keep evidence for Executor cores at "often 2–5 to balance parallelism, I/O, and GC" so the last production stage-Track - task reports, shuffle blocks, retries, and final output-remains testable.
When to avoid or be careful
- Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
- Do not conflate Executors with Driver. The second concept contributes different behavior: Long-lived JVM processes that run tasks, store shuffle/cache blocks, and are replaced after failures by the cluster manager.
- Release only after this guardrail is in place: Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs.
Driver / Executors / DAG Scheduler - roles, limits, and operating cost
Strengths: The application JVM/Python controller that owns the SparkContext, plan, scheduler state, and result collection. A Spark driver creates a logical plan, schedules a DAG through a cluster manager, and dispatches serializable task closures to executors that run partitions and report shuffle/execution state.
Watch out: Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
Strengths: Long-lived JVM processes that run tasks, store shuffle/cache blocks, and are replaced after failures by the cluster manager. In this workflow it supports: Schedule - tasks map to executor cores and partitions.
Watch out: The operating cost is real: split across execution, storage, user, and Spark reserved regions.
Strengths: The scheduler that translates a logical execution graph into jobs, shuffle stages, and partition-level tasks. Its output can be checked with Task target.
Watch out: Operating guardrail: Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Driver, and how would Executor cores reveal it?”
- “Why is Executors distinct from this behavior: the scheduler that translates a logical execution graph into jobs, shuffle stages, and partition-level tasks?”
- Production clue: Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
- Design probe: Keep results distributed, broadcast only small tables, size executors around memory/cores, set a cluster manager queue, and inspect driver GC and executor loss separately in the event and application logs.
Benchmarks & rules of thumb
- Executor cores
- often 2–5 to balance parallelism, I/O, and GC
- Executor memory
- split across execution, storage, user, and Spark reserved regions
- Task target
- roughly hundreds of milliseconds to minutes, not a few milliseconds
Common mistakes & follow-ups
Common interview mistakes
- Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
- Reporting success from a job exit code without checking Executor cores and Executor memory.
- Treating this example as complete without replay, rollback, or access boundaries:
spark.sql.shuffle.partitions=800is not automatically correct: a 10 TB join may need enough tasks, but 800 one-row partitions waste scheduler work; size partitions from bytes and task time rather than a copied default.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: The application JVM/Python controller that owns the SparkContext, plan, scheduler state, and result collection.
- What does the recovery plan do when this occurs? Collecting a distributed dataset to the driver creates a heap hotspot, a missing class on executor classpaths breaks serialization, and too-many tiny executors amplify shuffle and scheduling overhead.
- When is Driver insufficient for Executor memory, and what does adding Executors cost in Executor cores?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Apache Spark Architecture (Driver, Executors, Cluster Manager, DAG Scheduler) with data engineer interview Q&A and hands-on practice.