VOL. 01
← The learning path
FUNDAMENTALS / LESSON 05

Jobs, stages & tasks

Read the execution hierarchy without memorizing misleading formulas.

THE IDEA TO KEEP

An application runs jobs. Jobs are split into stages, and a stage has tasks that process its partitions.

Work at three scales

A job is work initiated to obtain a result. A stage groups tasks that can run without crossing a shuffle dependency. Within a stage, tasks operate on partitions. Task attempts can be retried, so attempts and distinct tasks are different counts.

Partitions are not CPU cores

In the simplified case of 12 ready tasks and four available task slots, execution needs at least three waves. That assumes one slot per task, similar task lengths, and no failures. Twelve partitions do not imply twelve machines.

Read the UI from the slow end

Find the slow stage, compare task durations, and inspect input sizes and shuffle metrics. One unusually slow task suggests a different investigation from every task being slow. Use evidence to distinguish imbalance from insufficient overall resources.

◈ Make it visible — explore the shuffle lab →Connect the concepts: the complete Spark execution flow →

Try it on a small dataset

Run this in a PySpark notebook with an existing spark session. Create a local session if needed. Examples are illustrative; this website does not execute Spark.

PYTHON / PYSPARK
from pyspark.sql import functions as F
events = spark.range(0, 120, 1, 4)
counts = (events.withColumn("bucket", F.col("id") % 3)
          .groupBy("bucket").count())
counts.explain("formatted")
counts.orderBy("bucket").show()
Expected result

Buckets 0, 1, and 2 each have count 40. Exact job/stage counts depend on the executed plan and configuration.

Result reasoned through on the small input; not runtime-tested against a Spark cluster.

Watch the assumption

A partition is a unit of data; a task is a unit of execution. AQE can change the number of downstream shuffle partitions.

EXPLAIN IT BACK

You have 200 tasks and 20 available slots. Will the stage take exactly ten task durations?

Say your answer out loud before opening the notes.

Reveal the reasoning

Ten waves is only a lower-bound model for uniform tasks with no overhead. Skew, scheduling, I/O, retries, and contention affect actual completion time.

Sources & verification

Core claims checked against Apache Spark 3.5.7 documentation and source references on 2026-09-13. Explanations, scenarios, and diagrams are original teaching material. Other releases and managed runtimes can differ.

Find a concept