Menu

Apache Spark interview question · Question 2 of 6

Explain Spark jobs, stages and tasks.

  • Medium
  • conceptual
  • ~6 min
  • High relevance
  • 2 min read
  • Updated Oct 2026

Short answer

When you call an action, such as count or write, Spark creates a job to compute it. The job is split into stages wherever data must be shuffled, because a wide step needs all the rows for a key in one place before it can continue. Each stage runs as a set of tasks, one per partition, in parallel on the executor cores. With Adaptive Query Execution, one action can appear as several jobs, because Spark re-plans after each shuffle.

On this page
  1. Detailed explanation
  2. Example
  3. Driver versus executors
  4. Common mistakes

Detailed explanation

Concept Created by Count determined by
Job An action (count, write, show) One or more per action
Stage Shuffle boundaries in the plan Number of wide transformations + 1 (roughly)
Task A partition in a stage Number of partitions in that stage

Example

Reading a dataset with 8 input partitions, filtering, then groupBy("country").count() and show():

  1. Job: triggered by show().
  2. Stage 1: read + filter + partial aggregation, 8 tasks (one per input partition), ending with shuffle write.
  3. Stage 2: shuffle read + final aggregation, as many tasks as shuffle partitions (often fewer after AQE coalescing).

Driver versus executors

The driver plans and schedules; executors run tasks and store shuffle and cached data. A slow driver usually means too much collect() or too many tiny tasks to schedule.

Common mistakes

  1. Saying each transformation is a stage (only shuffles create new stages).
  2. Equating tasks with executors (tasks map to partitions; executors provide cores).

By , Data Engineer and Founder of DataDank · Last reviewed Oct 2026 · Examples run on PySpark 4.2 in local mode; behaviour notes say where Spark 3.x differs

Progress is saved in this browser only. No account needed.

Search
Filter by type