Job, stage and task
| Also known as | Spark job, Spark stage, Spark task |
|---|---|
| Field | Distributed data processing |
| Key parts | Action, job, ShuffleMapStage, ResultStage, task, stage attempt
|
| Open source implementations | Apache Spark |
| Related | Directed acyclic graph (Spark), Shuffle, Narrow and wide transformations, Executor, Adaptive Query Execution |
In Apache Spark, a job is the parallel computation that one action (such as collect or save) starts; Spark divides each job into stages at shuffle boundaries, and each stage into tasks, one per partition, which run on executors.[1][2] These three terms are the units in which the Spark web UI, the driver logs and the scheduler describe work. Knowing how they map to code explains why one line of PySpark can show up as several jobs and hundreds of tasks.
What are a job, a stage and a task?
| Term | Definition in Spark | Created when | Seen in the UI as |
|---|---|---|---|
| Job | A parallel computation of many tasks, spawned in response to an action[1] | An action runs; the DAG scheduler receives it through submitJob[2]
|
A row in the Jobs tab |
| Stage | A set of tasks that compute the same function on different partitions of the same data; stages are separated at shuffle boundaries[2] | The DAG scheduler cuts the job's graph at each shuffle dependency[2] | A row in the Stages tab, and a box in the job's DAG visualization[3] |
| Task | A unit of work sent to one executor[1], which processes one partition | A stage is submitted as a TaskSet with one task per partition to compute[2] | A row in the task table of the stage detail page[3] |
Spark has two kinds of stage. A ShuffleMapStage writes map output files for a shuffle, and a ResultStage is the final stage that runs the action.[2] A stage can be shared by several jobs if they reuse the same data.
How does one action become jobs, stages and tasks?
The driver builds the plan, and the action hands it to the DAG scheduler as a job. Operations with narrow dependencies, such as map and filter, are pipelined together into one set of tasks per stage; operations with shuffle dependencies need one stage to write map output files and another to read them after a barrier.[2] See Narrow and wide transformations.
The number of tasks in a stage is the number of partitions it computes. A stage that reads files has one task per input partition, and file partitions hold at most spark.sql.files.maxPartitionBytes (default 128 MB) each; a stage after a shuffle has one task per shuffle partition, which for DataFrame and SQL queries is spark.sql.shuffle.partitions (default 200) unless Adaptive Query Execution changes it.[4] An executor runs at most spark.executor.cores divided by spark.task.cpus tasks at once, so the tasks of a large stage queue for free slots.[5]
Example
This PySpark aggregation needs one shuffle, because rows with the same key must meet in one task:
df = spark.range(1_000_000)
df.groupBy((df.id % 10).alias("m")).count().collect()
Run with local[2] on PySpark 4.3.0 and read back through SparkContext.statusTracker(), the same action produced these units:
| Setting | Jobs | Stages and tasks |
|---|---|---|
spark.sql.adaptive.enabled=false
|
1 job | Stage 0: 2 tasks (read the range and write shuffle files); stage 1: 200 tasks (read the shuffle and finish the count) |
spark.sql.adaptive.enabled=true (default)
|
2 jobs | Job 1: one stage of 2 tasks (the map side). Job 2: a reference to the same map stage, whose shuffle output already existed, and a result stage of 1 task, after AQE coalesced the 200 shuffle partitions into one |
The second row shows why job counts in the UI do not always match actions. AQE re-optimizes the plan during execution from runtime statistics,[4] and in this run it started the map side as its own job before planning the final stage. The DAG scheduler remembers which shuffle map stages have already produced output files and does not redo them;[2] the web UI lists such stages under "skipped".[3]
Reading the Spark UI with these terms
The Spark web UI follows the same hierarchy:[3]
- The Jobs tab lists each job with its description, duration, a stage summary and a task progress bar. A job's detail page shows the DAG visualization and the job's stages grouped as active, pending, completed, skipped and failed.
- The Stages tab lists all stages. Each stage shows input and output bytes, shuffle read (bytes read from earlier stages) and shuffle write (bytes written for later stages).
- A stage detail page shows summary metrics over all tasks (duration, GC time, scheduler delay, peak execution memory, shuffle read fetch wait time, shuffle spill to memory and disk) and a table with one row per task.
- The SQL / DataFrame tab has a detail page per query that lists the jobs and stages associated with it and shows its parsed, analyzed and optimized logical plans and physical plan. The stage DAG groups nodes by operation scope, such as
WholeStageCodegenandExchange, and annotates code generation IDs, so a stage can be traced back to operators in the physical plan.
Failures and retries
A task that fails is retried by the task scheduler; spark.task.maxFailures (default 4) is the number of continuous failures of one particular task before Spark gives up on the job, so the default allows three retries.[5] If a task fails because shuffle output from an earlier stage was lost, for example because an executor died, the DAG scheduler resubmits the earlier stage. Each run of a stage is called an attempt.[2]
Spark terms compared with Trino
Trino uses the words "stage" and "task" for related but different things.
| Apache Spark | Trino | |
|---|---|---|
| Stage | A set of tasks that actually run on executors, between two shuffle boundaries[2] | A model of part of the distributed query plan used by the coordinator; stages themselves do not run on workers[6] |
| Task | One unit of work on one partition, sent to one executor[1] | The implementation of a stage on a worker; tasks operate on splits[6] |
| Job | The work started by one action | No equivalent term; the unit is the query |
See also
- Directed acyclic graph (Spark)
- Narrow and wide transformations
- Shuffle
- Executor
- Adaptive Query Execution
- Lazy evaluation
References
- ↑ 1.0 1.1 1.2 1.3 Cluster Mode Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 DAGScheduler.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 3.0 3.1 3.2 3.3 Web UI (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 4.0 4.1 Performance Tuning (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 5.0 5.1 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 6.0 6.1 Trino concepts (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.