Jobs, Stages, Tasks & Narrow vs Wide Dependencies
Read how Spark splits work into jobs, stages, and tasks, and why wide deps force shuffles.
In plain words
Submit a complete execution job. Next, wide exchanges create stage boundaries. Finally, failed tasks rerun on available executors.
Think of it like…
A job is a construction project, stages are trade handoffs, and tasks are individual rooms; a shuffle is moving all materials between teams so the right room receives them.
Where you’ve seen it
A map and filter remain in one stage; join/groupBy creates a shuffle and at least new reduction stages, with one task processing each of spark.sql.shuffle.partitions output partitions.
Words you’ll hear
- Stages
- A sequence of stages forming one Spark action's execution graph.
- Tasks
- A single scheduling unit per partition inside a stage, running the same closure on one data slice.
- Wide Deps
- Transformations whose output may combine records from many partitions, such as joins and aggregations, requiring a shuffle.
- Operational boundary
- Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized. Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies.
Visual diagram
Theory & deep dive
Stages: the working mechanism
Each Spark action creates one or more jobs; a shuffle or execution boundary divides a job into stages, and a stage runs one task per input or shuffle partition.
Submit a complete execution job. Wide exchanges create stage boundaries, then one unit per partition per stage; this exposes the state governed by Wide Deps.
A map and filter remain in one stage; join/groupBy creates a shuffle and at least new reduction stages, with one task processing each of spark.sql.shuffle.partitions output partitions.
Jobs, Stages, Tasks & Narrow vs Wide Dependencies: failure mode and production response
Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies. Track Task parallelism as "executors times cores, but not all can be kept busy through one skewed stage", and make Shuffle partitions visible to the dataset owner.
How it works, step by step
Step 1 of 41. Action
Submit a complete execution job. Each Spark action creates one or more jobs; a shuffle or execution boundary divides a job into stages, and a stage runs one task per input or shuffle partition.
- Task parallelism
- executors times cores, but not all can be kept busy through one skewed stage
- Tasks
- A single scheduling unit per partition inside a stage, running the same closure on one data slice.
When to use it & trade-offs
What it is
Each Spark action creates one or more jobs; a shuffle or execution boundary divides a job into stages, and a stage runs one task per input or shuffle partition. A map and filter remain in one stage; join/groupBy creates a shuffle and at least new reduction stages, with one task processing each of spark.sql.shuffle.partitions output partitions.
Why it matters: Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized. Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies.
When to reach for it
- Read how Spark splits work into jobs, stages, and tasks, and why wide deps force shuffles.
- Choose Stages because it provides this capability: A sequence of stages forming one Spark action's execution graph.
- Keep evidence for Task parallelism at "executors times cores, but not all can be kept busy through one skewed stage" so the last production stage-Retry/complete - failed tasks rerun on available executors-remains testable.
When to avoid or be careful
- Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
- Do not conflate Tasks with Stages. The second concept contributes different behavior: A single scheduling unit per partition inside a stage, running the same closure on one data slice.
- Release only after this guardrail is in place: Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies.
Stages / Tasks / Wide Deps - roles, limits, and operating cost
Strengths: A sequence of stages forming one Spark action's execution graph. Each Spark action creates one or more jobs.
Watch out: Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
Strengths: A single scheduling unit per partition inside a stage, running the same closure on one data slice. In this workflow it supports: Task scheduling - one unit per partition per stage.
Watch out: The operating cost is real: set from shuffled bytes and target task duration.
Strengths: Transformations whose output may combine records from many partitions, such as joins and aggregations, requiring a shuffle. Its output can be checked with Stage retries.
Watch out: Operating guardrail: Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Stages, and how would Task parallelism reveal it?”
- “Why is Tasks distinct from this behavior: transformations whose output may combine records from many partitions, such as joins and aggregations, requiring a shuffle?”
- Production clue: Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
- Design probe: Count stage input and shuffle partitions, target task partitions around executor parallelism and hundreds of MB, choose narrow transformations where possible, and break or salting skewed wide dependencies.
Benchmarks & rules of thumb
- Task parallelism
- executors times cores, but not all can be kept busy through one skewed stage
- Shuffle partitions
- set from shuffled bytes and target task duration
- Stage retries
- driver resubmits failed partitions unless failures exhaust policy
Common mistakes & follow-ups
Common interview mistakes
- Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
- Reporting success from a job exit code without checking Task parallelism and Shuffle partitions.
- Treating this example as complete without replay, rollback, or access boundaries: A
mapand filter remain in one stage;join/groupBycreates a shuffle and at least new reduction stages, with one task processing each ofspark.sql.shuffle.partitionsoutput partitions.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: A sequence of stages forming one Spark action's execution graph.
- What does the recovery plan do when this occurs? Thousands of tiny tasks waste driver scheduling time, while a few huge partitions make one task dominate and create the false impression that the cluster is fully utilized.
- When is Stages insufficient for Shuffle partitions, and what does adding Tasks cost in Task parallelism?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Jobs, Stages, Tasks & Narrow vs Wide Dependencies with data engineer interview Q&A and hands-on practice.