TL;DR
Data lineage is a record of where each dataset came from: which inputs were read, and which step turned them into the output. Companies store it as a graph in which each dataset is a node and each arrow points from an input to the dataset built from it. With that graph you can trace a wrong number back to its raw source, and you can list every report that a bad source has touched. Some data systems also use lineage to rebuild lost data instead of storing extra copies.
Builds on: Directed Acyclic Graph, Immutability · Leads to: the Spark RDD design, which uses lineage for recovery
Where it's used
Debugging a wrong dashboard. A weekly revenue chart shows a drop that nobody expected. An analyst follows the lineage arrows backwards from the chart to the table it reads, then to the table that table reads, and so on, until they reach the raw event feed. Each step names the job that made it. Without lineage the analyst has to read every job's code to find the cause.
Finding every report touched by a bad source. When a currency-rate feed is found to be wrong for one day, lineage lists every table and report derived from it. Those are the outputs that must be rebuilt or flagged. A team that does not know this list either rebuilds everything, which is slow, or misses a report, which is worse.
Compliance and audit. Regulated firms often must show where a reported figure came from and which processing steps touched it. A lineage record gives a complete answer for every derived table, provided every job reports its inputs.
Fault recovery in cluster computing. The 2012 Spark paper on resilient distributed datasets (RDDs) stores, for each RDD, the chain of operations that produced it from stable input data. If a machine holding part of an RDD fails, Spark recomputes only the lost partition by replaying that chain, instead of keeping a second copy of all the data. The lineage graph is what makes that recovery possible.
How it works
Take a tiny pipeline with four datasets. The raw orders table is read from the shop's system. A cleaning job removes bad rows and produces a clean orders table. A daily revenue job sums the clean rows. A dashboard reads the daily revenue. The lineage graph records this as:
flowchart LR A[raw orders] --> B[clean orders] B --> C[daily revenue] C --> D[dashboard]
Here is one tiny instance traced step by step. The amounts are small and round.
- Start with the raw rows. The raw orders table has four rows with amounts 10, 20, -5 and 30. The negative amount is a refund entered by mistake. Check: four rows, one of them negative.
- Run the cleaning job. The job keeps only rows with a positive amount. Its output, clean orders, has three rows: 10, 20 and 30. Check: the -5 row is gone, and nothing else changed.
- Record the edge. The lineage graph gets an arrow from raw orders to clean orders, and the cleaning job's name is stored on that arrow. Now any reader can see that clean orders was built from raw orders. Check: the arrow points from input to output, and it points one way only.
- Run the revenue job. It sums the clean rows: 10 + 20 + 30 = 60. The daily revenue table holds one number, 60. Check: 10 plus 20 is 30, and 30 plus 30 is 60.
- Record the rest of the chain. Arrows now run raw orders to clean orders, clean orders to daily revenue, and daily revenue to the dashboard. Starting from the dashboard, you can walk back to raw orders in three steps. Check: three arrows make a path of length three.
- Use the graph when something breaks. Suppose the raw orders feed turns out to be wrong. Walking forward from raw orders reaches clean orders, daily revenue and the dashboard. All three must be rebuilt, and the lineage graph gives that list without anyone reading the job code. Check: the list has three entries, and the path from raw orders to each of them is in the graph.
The math
The lineage graph
A lineage graph is a directed graph where each vertex is a dataset and each edge means that was computed from by some job. The graph is acyclic: no dataset can be an ancestor of itself. This is the directed acyclic graph property, and it holds because a dataset is only built from datasets that existed before it.
Each derived dataset has a function that the job computes, and inputs , its set of parents in the graph. The stored value of is
Immutability is what makes this safe: once a dataset is written, nothing changes it, so each formula gives one fixed result. See Immutability.
Step 3 in symbols: recording an edge
Recording a job that reads and writes adds one edge, . The graph stays acyclic as long as the new edge does not close a loop. Since is new when the job writes it, it has no outgoing edges yet, and no loop can form.
Step 6 in symbols: what must be rebuilt
If a source dataset is wrong, the datasets that must be rebuilt are its descendants: all for which there is a directed path from to . Write this set as
The rebuild order is a topological order of this set: an ordering in which every dataset comes after its parents. Computing datasets in that order means each job finds its inputs already correct.
Recovery by recomputation
In the RDD design, a lost partition is rebuilt by recursion. If is stored, return it. If not, rebuild each parent in the same way, then apply . In symbols,
The recursion stops at stored data, so the cost depends on how far back the nearest stored copy is.
Worked examples
Use the pipeline from How it works. The graph is raw orders clean orders daily revenue dashboard.
- Compute the clean orders from the raw ones: keep positive amounts from 10, 20, -5 and 30. Result: 10, 20, 30.
- Compute the daily revenue as the sum: .
- Compute the dashboard value, which equals the daily revenue, 60.
- Now suppose the -5 row was a real sale that the cleaning job wrongly dropped. Trace the lineage forward from clean orders. The descendants are daily revenue and dashboard, so both must be rebuilt.
- Interpretation: the number 60 is wrong, but the lineage tells you exactly which two outputs to recompute, and that the raw table itself is not the thing to fix.
Take four datasets with edges , , and . This shape, two paths that meet again, is common when one table feeds two reports that are later combined.
- Find the descendants of . From you can reach directly and directly. From you reach , and from you also reach . So .
- Find the descendants of . The only path from goes to . So .
- Find the descendants of . has no outgoing edges, so .
- Give a rebuild order for the case when is wrong. A topological order is , or . Both put last, because needs and first.
- Interpretation: appears once in the rebuild list even though two paths reach it. The set form of the answer does not count paths, only datasets, so each dataset is rebuilt once.
A company's weekly report reads two sources through a chain of jobs. Raw events feed a session table and an orders table. The session table feeds a daily-users table, and the orders table, together with a currency-rate table, feeds a revenue table. Both the daily-users table and the revenue table feed the weekly report.
- Write the edges. Raw events goes to sessions, and raw events goes to orders. Sessions goes to daily users. Orders and currency rates go to revenue. Daily users and revenue go to the weekly report.
- Suppose the raw event feed was corrupted on Monday. Find its descendants: sessions, orders, daily users, revenue and the weekly report. That is five datasets to rebuild.
- Suppose instead the currency-rate table was wrong. Its only child is revenue, and revenue's only child is the weekly report. So the rebuild list is two datasets: revenue and the weekly report.
- Compare the two cases. The raw feed touches five datasets and the currency table touches two. The lineage graph shows the difference without any job code being read.
- Try it: which datasets must be rebuilt if only the daily-users table is found to be wrong? Answer: only the weekly report. Daily users has one child, the weekly report, and nothing else depends on it.
Common mistakes and tradeoffs
It is tempting to think that lineage tells you the data is correct. In fact lineage only records where data came from. A wrong job still gets recorded as a correct edge. Lineage helps you find the cause of a wrong value, but you still need tests to find the wrong value.
It is tempting to think that table-level lineage is enough. In fact it tells you that a report depends on a table, not which rows of the table produced a particular number. Row-level, or why-provenance, records the input rows behind each output row. It is much larger and harder to collect, so most teams stop at table level unless an audit requires more.
It is tempting to think that rebuilding is always cheaper than storing copies. In fact recomputation costs time and compute, and a long chain may take hours to replay. Systems therefore mix the two: they keep some intermediate results stored, using Checkpointing, and recompute only from the nearest stored copy.
It is tempting to think that a cycle in the graph is a valid way to describe an update. In fact a dataset that is derived from itself, for example by appending to itself each day, breaks the graph. Systems handle this by giving each version its own node, which keeps the graph acyclic. This is the same idea as Immutability applied to versions.
When to use lineage: when results must be traced back, when a bad source must be followed through many jobs, or when recovery should rebuild lost data instead of copying all of it.
When not to use it: a single job with one table has nothing to trace. Full row-level lineage is not worth its cost for ordinary dashboards.
Alternatives: storing a full copy of each dataset (simple, but costly in space and not a record of the steps), and replicating data across machines for fault tolerance (which avoids recomputation but needs more storage).
History
Database researchers began studying provenance, the origin of query results, in the early 2000s. Peter Buneman and colleagues gave the standard vocabulary of why and where provenance. Data warehouses and reporting tools then needed the same record for auditing and debugging, and most of the practice grew out of that need.
The idea became central to cluster computing with the 2012 Spark paper on resilient distributed datasets. Its authors used lineage for recovery: each dataset knows how it was computed, so a lost piece can be recomputed rather than restored from a copy. That design showed that a lineage graph can serve two jobs at once, tracing results and recovering data, and later data platforms adopted both uses.
Recap
- Data lineage records which datasets were read to make each derived dataset, as a directed acyclic graph.
- Tracing a value back to its source means walking the graph backwards; finding everything a bad source affected means walking it forwards.
- The datasets to rebuild after a source changes are its descendants, rebuilt in a topological order.
- In cluster computing, lineage lets a lost piece be recomputed from its nearest stored ancestor.
- Next, read the Spark RDD paper for lineage used in fault recovery, and Dataflow Analysis for the same graph idea applied to programs instead of data.
Check yourself
QuestionWhat does a data lineage graph store, and why is it acyclic?Show answer
It stores one node per dataset and one arrow from each input to each dataset computed from it. It is acyclic because a dataset is built only from datasets that already exist, so no dataset can be its own ancestor.
QuestionA pipeline has edges A to B, B to C and A to D. Which datasets must be rebuilt if A is wrong, and which if B is wrong?Show answer
If A is wrong, the descendants of A are B, C and D, so all three are rebuilt. If B is wrong, its only descendant is C, so only C is rebuilt. Note that D is not affected by B, because there is no path from B to D.
QuestionWhy does the RDD design rebuild a lost partition from its parents instead of keeping a second copy of every partition?Show answer
Storing a second copy of all data costs a lot of memory and storage. Since each partition's parents and transformation are recorded in the lineage, a lost partition can be recomputed from the nearest stored data, which is cheaper in space, at the cost of some recomputation time.
QuestionA chain of jobs runs for a long time before a failure. Why might a system store some intermediate results rather than rebuilding everything from raw data?Show answer
Recomputing from raw data repeats all the work in the chain, which can take hours. Storing some intermediate results shortens the recomputation, because rebuilding can start from the nearest stored result instead of the raw source.