Part XVII — Checkpointing vs Lineage: The Fault-Tolerance Trade You Misconfigure
From the publisher’s feed, collected in the ZeroLabs newsroom.
Spark’s lineage is the most elegant recovery mechanism in distributed computing — until your iterative job’s DAG grows so long that remembering how the data was built costs more than the data itself. Checkpointing cuts the chain. The question is what you pay for the scissors, and most teams get the answer wrong in both directions.Part I | Part II | Part III | Part IV | Part V | Part VI | Part VII | Part VIII | Part IX | Part X | Part XI | Part XII | Part XIII | Part XIV | Part XV | Part XVI | Part XVIIThe Job That Got Slower Every Single IterationThe entity-resolution job ran 120 iterations. Iteration 1 took 42 seconds. Iteration 30 took 6 minutes. By iteration 90, each pass was taking 14 minutes, and the whole thing was on track to blow past its 12-hour SLA window before iteration 110. Nobody had changed the code in weeks. The data volume was flat. The cluster was healthy. The job was simply, deterministically, getting slower every single time it looped — like a runner accumulating weights.Then came the real incident. At 4:12 AM, on iteration 118 of 120, a spot instance was reclaimed and took two executors with it. Spark did exactly what it was designed to do: it recomputed the lost partitions from lineage. The problem was the lineage. To rebuild those partitions, it had to replay 117 iterations of joins and aggregations — every shuffle, every stage, all the way back to the raw input. Recovery took 6 hours and 40 minutes. The two lost executors cost us nearly seven hours of cluster time and a missed downstream SLA that paged three teams.The post-mortem was one line long: we had 118 iterations of lineage and zero checkpoints. The DAG the driver was carrying had grown to tens of thousands of nodes. DAGScheduler was spending longer planning each iteration than the executors spent running it — planning cost grows with DAG depth, and we had built the deepest DAG in the company’s history one innocent loop at a time. The driver was also spending 40% of its time in garbage collection just holding the lineage graph (Part V’s memory lesson, applied to the driver instead of the heap).So: when does remembering how your data was built become more expensive than the data itself — and what does it actually cost to forget on purpose?The Mechanic Underneath: Lineage Is a Promise, and Promises CompoundSpark’s core fault-tolerance idea is disarmingly simple: instead of replicating data, remember how it was built. Every RDD and DataFrame carries its lineage — the graph of transformations from the source. Lose a partition, and Spark replays the lineage to rebuild exactly that partition. No replication overhead, no write-ahead cost during the happy path. For a ten-stage ETL, this is nearly free and brilliantly robust.But lineage is a promise that compounds. In an iterative algorithm — PageRank, ALS, K-means, our entity-resolution loop — each iteration appends to the DAG. After n iterations, the lineage graph has depth n, and three costs grow with it. First, recovery cost: rebuilding a lost partition means replaying every stage back to the last materialization point, so recovery time is roughly lineage depth × per-stage cost. Our 6h40m recovery was not bad luck; it was arithmetic. Second, scheduling cost: the DAGScheduler traverses the DAG to plan each job, and planning time grows with graph size — at iteration 90, planning alone took minutes. Third, driver memory: the entire lineage graph lives on the driver, and tens of thousands of nodes with their metadata will eventually push the driver into GC hell. Lineage is free until the day it is the most expensive thing in your architecture.Checkpointing is the deliberate decision to stop paying the compounding cost: materialize the data to stable storage (or executor memory), and cut the lineage at that point. Everything before the checkpoint is forgotten; recovery replays only from the checkpoint forward. You trade write cost now for bounded recovery cost later. The entire art of this topic is choosing where to cut, how often, and which kind of scissors to use — because each choice has a failure mode that teams discover at 4 AM.Reliable Checkpointing Cuts the Chain — For a PriceRDD.checkpoint() (and Dataset.checkpoint()) writes the data to the checkpoint directory — HDFS, S3, any reliable filesystem you configure via sparkContext.setCheckpointDir() — and then truncates the lineage, pointing the RDD's parent at the checkpointed files instead of the full history. Recovery from a checkpoint replays at most the stages since the last cut. In our job, checkpointing every 10 iterations would have bounded recovery to 10 stages instead of 118 — turning 6h40m into roughly 25 minutes.The price is write amplification. A reliable checkpoint is a full materialization: every byte of the checkpointed dataset gets written to durable storage, with all the serialization and I/O cost that implies. Checkpoint a 2TB iterative state every 10 iterations over 120 iterations and you have written 24TB to S3 that your lineage would never have written. On S3 specifically, the cost is worse than it looks — no atomic renames, high per-request latency — and checkpoint writes go through the same object-store path as everything else. Teams that checkpoint every iteration “to be safe” often discover their fault-tolerance mechanism is the slowest stage in the job. The checkpoint directory also needs lifecycle management: Spark does not clean up old checkpoints for RDDs automatically, and an unmonitored checkpoint dir is a slow-growing storage bill with your name on it.Local Checkpointing Is Faster and Lies About DurabilitylocalCheckpoint() — RDD.localCheckpoint() and Dataset.localCheckpoint() — cuts the lineage too, but materializes the data on the executors' local disks (or in memory, depending on storage level) instead of reliable storage. It is dramatically faster than a reliable checkpoint: no HDFS/S3 round trip, just a local write. For iterative ML loops where the dominant cost is DAG growth rather than executor loss, this is often the right tool.But read the contract carefully: local checkpoint data dies with the executor. If the executor holding your locally-checkpointed partition is lost, Spark falls back to recomputing from the truncated lineage — which still exists underneath, because local checkpointing does not delete the original lineage, it just stops extending it. In practice this means local checkpointing bounds scheduling cost and driver memory (the DAG stops growing) but only partially bounds recovery cost (the underlying lineage is still replayable, just not re-traversed for planning). It is a scheduler optimization wearing a fault-tolerance costume. Our 4 AM executor loss would still have hurt with local checkpoints — less, but not the 25-minute story. Know which guarantee you are actually buying.RDD Checkpointing Is Lazy; DataFrame Checkpointing Is NotA gotcha that has bitten every team exactly once: RDD.checkpoint() is lazy — it marks the RDD for checkpointing, but nothing is written until the next action triggers computation. Dataset.checkpoint() (the DataFrame API), by contrast, is eager — it triggers a job immediately and blocks until the checkpoint is materialized. Mix them in the same codebase without knowing this and you get either checkpoints that never materialize (RDD marked but no action follows before the driver moves on) or mysterious blocking jobs in the middle of your pipeline (DataFrame checkpoint firing eagerly inside a loop). The eager DataFrame behavior is usually what you want in an iterative loop — you want the cut to happen now, deterministically, every k iterations — but you must budget for it: each eager checkpoint inside the loop is a full extra job with its own stages. Count it in your iteration-time math or your "optimization" will look like a regression in the UI.Streaming Checkpoints Are a Different AnimalStructured Streaming’s checkpointing (Part VIII’s territory) shares the name but not the mechanics. The checkpoint location (checkpointLocation option, or spark.sql.streaming.checkpointLocation) stores three things: source offsets, the write-ahead log of processed batches, and the serialized state store for stateful operations. Recovery replays from the last committed offset — exactly-once semantics depend on the sink supporting idempotent writes, which is why the docs pair checkpointing with foreachBatch idempotency patterns. Two sharp edges: checkpoint state is tied to your query's code — change the projection, the schema, or the stateful logic incompatibly and the old checkpoint becomes unloadable, forcing you to start from a fresh location (or face cryptic deserialization errors); and the default spark.sql.streaming.minBatchesToRetain (100) bounds how much history the checkpoint keeps, which interacts with late-data handling. Streaming checkpointing is not optional — without a checkpoint location, a streaming query cannot recover at all — but it is also not free: state serialization for large keyed state is a real, ongoing write cost on every trigger.The Fix, and What It CostThe naive version was our original loop — 120 iterations, pure lineage, no cuts:# Naive: 120 iterations of pure lineage. DAG depth grows to 120, driver holds# the entire graph, and ONE executor loss replays ALL 118 prior iterations.# result = result.join(updates, "id").groupBy("id").agg(...) # in a loop, no checkpoint# Optimized: cut the lineage every 10 iterations with a RELIABLE checkpoint.# Recovery is now bounded to sc.setCheckpointDir("s3://our-bucket/checkpoints/entity-resolve") # reliable storeresult = base_dffor i in range(120): result = result.join(updates, "id").groupBy("id").agg(...) # the iterative step if i % 10 == 0 and i > 0: result = result.checkpoint() # eager: materializes NOW, truncates lineage # checkpoint dir lifecycle: old cuts cleaned by retention job, not SparkFor the tight inner loop of the ML variant we used localCheckpoint() instead — the DAG-growth problem dominated and executor loss was rare on our on-demand pool — reserving reliable checkpoints for every 30th iteration as the durability backstop. Two scissors, each used where its guarantee matches the risk.The measured result on the next full run: per-iteration time stabilized at 55–70 seconds across all 120 iterations (vs. degrading from 42s to 14min), total runtime 11h20m → 2h35m, and a chaos test — killing two executors at iteration 100 — recovered in 22 minutes instead of 6h40m. The checkpoint writes added ~9 minutes of I/O across the whole run. Nine minutes of writes bought back nine hours of compounding lineage cost. That is the entire trade, expressed as a number.The Catch: Checkpointing Can Quietly Make Everything WorseFour ways the cure becomes the disease. First, checkpointing too often: every reliable checkpoint is a full write of the dataset. Checkpoint every iteration of a 2TB state and you have built a write-amplification machine that dwarfs the lineage cost you were avoiding — profile the write cost per checkpoint before choosing the interval. Second, checkpointing on slow storage: S3 checkpoint writes without S3A tuning (or worse, without fs.s3a committer settings) serialize your "fast" iterative loop behind object-store latency; the checkpoint dir belongs on fast storage or a tuned path. Third, localCheckpoint's false confidence: it does not bound recovery the way teams assume — the underlying lineage survives, and executor loss still replays it. If your post-mortem says "but we had checkpoints," check which kind. Fourth, streaming checkpoint incompatibility: evolving a stateful streaming query's logic without migrating the checkpoint location produces failures that look like data corruption but are really version skew — treat checkpoint locations as versioned artifacts, not scratch space. Checkpointing is a sharp tool. Grip it by the handle.TakeawaysLineage cost compounds with DAG depth: recovery time ≈ depth × stage cost, scheduling time grows with graph size, and the driver holds all of it. Iterative jobs must cut the chain.Reliable checkpointing bounds recovery for a write price: every cut is a full materialization. Size the interval from measured write cost, not from superstition.Local checkpointing is a scheduler optimization, not durability: it stops DAG growth but the underlying lineage survives executor loss. Buy it for planning cost, not for recovery.RDD checkpointing is lazy, DataFrame checkpointing is eager: a marked-but-never-materialized RDD checkpoint protects nothing; an eager DataFrame checkpoint inside a loop is a full extra job per cut.Streaming checkpoints are versioned state: offsets, WAL, and serialized state stores. Change query logic incompatibly and the old checkpoint is unloadable — treat locations as versioned.Clean up after yourself: Spark does not retire old RDD checkpoints. An unmonitored checkpoint directory is a storage bill growing in the dark.Lineage remembers everything for free, until the remembering costs more than the data. Checkpointing is how you choose what to forget — deliberately, measurably, and before 4 AM chooses for you.If this saved you a 3 AM pager incident, follow me on Medium for Twice a week for the next 3 Months of Advanced Data Engineering & AI. Let’s connect on LinkedIn and X.Part XVII — Checkpointing vs Lineage: The Fault-Tolerance Trade You Misconfigure was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.