The full answer
Lineage is the record of how each DataFrame or RDD was derived from its sources: the chain of transformations Spark would need to replay to rebuild it. The DAG (directed acyclic graph) is how Spark organises that chain for execution: operations are nodes, dependencies are edges, and the scheduler cuts the graph into stages at shuffle boundaries. Lineage is mainly about recovery; the DAG is mainly about execution.
Lineage
- Every transformation produces a new dataset that remembers its parent and the operation applied.
- If an executor is lost, Spark recomputes only the lost partitions by replaying their lineage from the source or from the last shuffle output that still exists.
- It needs no replication of intermediate data, which is why it is efficient.
- Very long lineages (iterative algorithms, loops that keep transforming the same DataFrame) make planning and recovery slow;
checkpoint()orlocalCheckpoint()saves the data and truncates the lineage, as does writing an intermediate table.
You can see it with rdd.toDebugString() for RDDs, or the logical plan in df.explain(True) for DataFrames.
DAG
- When an action runs, the DataFrame's optimised physical plan (or the RDD lineage) is handed to the DAG scheduler.
- The scheduler walks the dependencies backward from the final result. Narrow dependencies are pipelined into the same stage; each wide dependency (a shuffle) starts a new stage.
- Stages are submitted in dependency order; independent stages can run in parallel.
- Each stage becomes a set of tasks, one per partition, handed to the task scheduler to run on executors.
- If a shuffle's output is lost, the scheduler re-runs the parent stage that produced it.
Example
from pyspark.sql import functions as F
daily = (spark.read.parquet("/data/events") # stage 1: scan
.filter(F.col("type") == "purchase") # stage 1 (narrow)
.groupBy("event_date").agg(F.count("*"))) # shuffle → stage 2
customers = spark.read.parquet("/data/customers") # can run in parallel
Seeing it The Spark UI shows a DAG visualisation for each job and stage, and the SQL tab shows the physical plan as a graph with metrics per operator, such as rows output, time and spill. It is the first place to look when a stage is slow.
Why both matter The DAG lets Spark plan the whole job, pipeline narrow operations and minimise shuffles. Lineage lets it recover from failures without the cost of replicating data. Together they give Spark fault-tolerant, optimised execution.
Last updated 16 October 2026
Sources