Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 63/ 160
04. Big Data Processing & Apache Spark

Apache Spark Architecture (Driver, Executors, Cluster Manager, DAG Scheduler)

Map the driver, executors, cluster managers, and DAG scheduler that execute your Spark application.

IntermediateDriver · Executors · DAG Scheduler3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Apache Spark Architecture in one concrete design

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.

Key takeaway: 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

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
Driver

1. 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.

driver starts and requests executor resources
Key numbers at this step
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

Driver
Best for: The application JVM/Python controller that owns the SparkContext, plan, scheduler state, and result collection.

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.

Executors
Best for: Long-lived JVM processes that run tasks, store shuffle/cache blocks, and are replaced after failures by the cluster manager.

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.

DAG Scheduler
Best for: The scheduler that translates a logical execution graph into jobs, shuffle stages, and partition-level tasks.

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=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.

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?
Interview tip: Lead with the data path and failure boundary: 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. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Hadoop Ecosystem Overview (HDFS, YARN) & Why Spark Replaced MapReduce
Next topic
Transformations vs Actions & Lazy Evaluation