IntermediateSpark · 14 min · 17 challenges

Fault Tolerance: Intermediate

Say the nightly Spark job at Airbnb totals yesterday's bookings per host into a payouts table that finance reads at 6am. At 02:40 its driver runs out of memory mid-write and the job fails. The on-call engineer presses rerun. Whether a host ends up paid twice or only partly depends on how that job commits files and replaces partitions, and on how it merges changes when its work is replayed.

Atomic Writes

Daily Life
Interviews
Writing a 1,000-partition DataFrame runs 1,000 tasks, and each task writes its own Parquet file. Those tasks finish minutes apart and some of them fail and run again. The job itself can die at any moment. If every task wrote straight into the destination, a reader polling it would see 400 files at 02:01 and 700 at 02:03. A crash would leave a table that is 70% complete and looks finished, and a retried task could leave 2 copies of the same part file. Spark prevents all 3 problems with a commit protocol: tasks write where no reader looks, and the driver publishes the result at the end.

Write first, publish later

For file sources, Spark writes through a committer, FileOutputCommitter, using its algorithm version 1 by default. Task output lives under a hidden _temporary directory inside the destination until the job finishes. When Spark lists a table it skips every path whose name starts with _ or ., so nothing under _temporary is ever read as data.

StepRuns onWhat happensReaders see it
Task writeExecutorThe attempt writes `part-00042-*.parquet` under `_temporary/0/_temporary/attempt_*/`No
Task commitExecutor, once the driver agreesThe attempt directory is renamed to `_temporary/0/task_*/`No
Job commitDriver, after the last taskEach committed file is renamed into the destination, then `_temporary` is deletedFile by file
MarkerDriverAn empty `_SUCCESS` file is written in the destinationYes: the output is complete
executors
Task attempts
PARTITIONS1000
_temporary/0/_temporary
Attempt dirs
driver: OutputCommitCoordinator
Commit check
_temporary/0/task_*
Committed task dirs
driver: renames
Job commit
then _SUCCESS
part files + _SUCCESS
Destination
waits for _SUCCESS
Downstream job

Output moves rightward only by rename, and the downstream job reads nothing until _SUCCESS exists.

One winner per task

A task can run more than once. An attempt that throws partway is retried on another executor, and an executor that stops answering heartbeats is presumed dead even though it may still be writing. So 2 attempts of task 42 can each finish a complete file. Before renaming its directory, an attempt asks the driver for permission. The driver's OutputCommitCoordinator says yes to the first attempt that asks for each partition and no to every later one. A refused attempt aborts, and anything it left behind goes when job commit deletes _temporary. Exactly 1 part-00042 reaches the destination.

What a crash leaves behind

The job dies duringThe destination holdsA reader waiting for _SUCCESS
Task writes`_temporary` onlySees nothing
Task commits`_temporary`, with some task directories committedSees nothing
Job commitSome part files and no `_SUCCESS`Keeps waiting and never reads the partial files
Nothing: it finishedEvery part file and `_SUCCESS`Reads the complete output

Job commit is a loop on the driver, 1 rename per file. Each rename is atomic and the loop is not, which is the third row. The all-or-nothing view a downstream job gets comes from the marker: Spark writes _SUCCESS after the last rename, so a consumer that waits for it reads every file or none. A consumer that only checks whether the directory exists can read part of a job.

Algorithm version 2

✓Version 1, the default
  • Task commit renames into _temporary/0/task_*
  • Job commit renames every file on the driver
  • Nothing appears in the destination before job commit
  • Job commit slows as the file count grows
✗Version 2
  • Task commit renames straight into the destination
  • Job commit does little beyond writing _SUCCESS
  • Finished tasks' files are visible mid-job and after a crash
  • Spark's configuration docs warn it may cause a correctness issue

The setting is spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version. Version 2 removes the driver's rename loop, which shortens commits for jobs with many files, and gives up the property this section is about: a reader can see half a job's output with no marker to warn it. Keep version 1 for any table someone reads while you write it.

TIP
In the Spark UI, when every task of a write has finished but the job keeps running, the driver is in job commit, renaming files. That gap grows with the file count, so 40,000 small files cost far more there than 400 large ones.
Multiple Choice

A job writing 1,000 part files with the default committer dies after the driver has renamed 600 of them into the destination. A downstream job checks the destination every minute. What does it find, and what should it do?

Overwrite vs Append

Daily Life
Interviews

The commit protocol makes a single run all-or-nothing. Pipelines run many times: the job for 2024-03-14 fails at 01:00 and is rerun at 03:00, a bug fix triggers a backfill of 30 days, a scheduler retries a run it thought had hung. Each rerun writes into a table that already holds data, and the save mode decides what happens to the rows that are there. Here is a daily job that counts views per page for 1 day of clickstream_raw.

from pyspark.sql import functions as F
run_day = "2024-03-14"
daily = (spark.table("clickstream_raw")
.filter(F.col("event_day") == run_day)
.groupBy("event_day", "page_id")
.agg(F.count("*").alias("views")))
daily.write.mode("append").partitionBy("event_day").parquet("/warehouse/page_counts")

The first run adds its part files under event_day=2024-03-14. The rerun adds a second set: each write names its files with an id unique to that job, so the new files land beside the old ones without replacing any. The day now holds every row twice, and a dashboard summing views reports double.

event_day=2024-03-14 after 1 run
filepage_idviews
part-00000-a1f37120
part-00001-a1f3945
After a rerun with append
filepage_idviews
part-00000-a1f37120
part-00001-a1f3945
part-00000-c7d27120
part-00001-c7d2945

Overwrite deletes more than the day

Switching to mode("overwrite") stops the duplication and introduces a worse failure. With partitionBy, overwrite follows spark.sql.sources.partitionOverwriteMode, whose default is static. In static mode Spark deletes every partition matching the write's partition spec before writing, and a DataFrame write carries no spec, so it matches all of them. The run for 2024-03-14 empties the table and leaves 1 day in it.

Before: partitions on disk
event_dayfiles
2024-03-122
2024-03-132
2024-03-142
After a static overwrite for 2024-03-14
event_dayfiles
2024-03-142

Dynamic mode replaces the days you wrote

spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic")
daily.write.mode("overwrite").partitionBy("event_day").parquet("/warehouse/page_counts")

In dynamic mode, tasks write into a staging directory, .spark-staging- plus the job id, under the destination. At job commit the driver deletes each partition directory the job produced rows for and moves the new one into its place, while partitions the job never wrote stay as they were. Rerunning 2024-03-14 swaps that day's files for new files holding the same rows; the table after 5 runs is identical to the table after 1. A 30-day backfill becomes 1 job that filters the 30 days and writes them once, replacing each partition exactly once.

A rerunnable daily write
  • ▸Reads a slice of input fixed by a parameter, run_day, instead of whatever arrived since the last run
  • ▸Writes the partitions that slice maps to, with the partition value taken from the rows
  • ▸Replaces each of those partitions whole; dynamic overwrite does this, and so does writing to the partition's own path
  • ▸Never overwrites the path it reads from, which can delete its own input mid-job

When the fixed day has no rows

Dynamic mode replaces only partitions that receive rows. Suppose 2024-03-14 was loaded from a corrupt file and the fixed rerun filters out every row. The job writes nothing for that day, so nothing is replaced, and the corrupt partition outlives a run that reported success. When a day must equal the job's output even if that output is empty, write to the partition's path:
(daily.drop("event_day")
.write.mode("overwrite")
.parquet(f"/warehouse/page_counts/event_day={run_day}"))

Overwrite on that path clears the directory whatever the row count. Dropping event_day keeps the column out of the files, since a reader of the table takes it from the directory name.

WriteA rerun of 2024-03-14Watch for
`append`Adds the day's rows againDuplicates on every retry
`overwrite`, static, with `partitionBy`Deletes every day, writes 1It is the default setting
`overwrite`, dynamic, with `partitionBy`Replaces 2024-03-14 onlyA day with 0 rows is left untouched
`overwrite` to `event_day=2024-03-14`Replaces that day, even with 0 rows1 partition per write
Multiple Choice

A job runs with default settings and ends with out.write.mode("overwrite").partitionBy("ds").parquet(path). The table at path holds 90 days. The job is rerun for ds 2024-03-10 to fix a bug. What does the table hold afterwards?

Idempotent Upserts

Daily Life
Interviews
Day partitions work when every row belongs to the day it arrived. A listings table breaks that: it holds 1 row per listing, and a listing created on March 2 can change price on March 14 and again on March 15. No day owns that row, so appending each day's changes leaves 3 versions of it, and overwriting a day keeps only the listings that changed that day. The table needs an upsert: insert new keys and update existing ones.

Rebuild from inputs that never change

A Parquet file is written once and never edited, so in plain files an upsert is a rewrite. Read yesterday's snapshot, union today's changes, keep the newest version of each key, and write the result as today's snapshot in a directory of its own. Since yesterday's snapshot is never touched, rerunning the 2024-03-14 merge sees exactly the inputs the first attempt saw, and its output at ds=2024-03-14 comes out the same however many times it runs.

Parquet
Snapshot ds=2024-03-13
read only
listing_attribute_changes
Changes 2024-03-14
Spark window
Keep latest per key
PARTITIONS200
Parquet
Snapshot ds=2024-03-14
IDEMPOTENCYoverwrite its own ds
reads ds=2024-03-14
Next day's merge

Each snapshot is built from the one before it and is never written again after its own day.

The animation runs that merge on a snapshot of 3 listings and 5 change rows. One change arrived twice because the upstream feed redelivered it.
from pyspark.sql import functions as F
from pyspark.sql.window import Window
merged = snapshot.unionByName(changes)
w = Window.partitionBy("listing_ref").orderBy(F.col("change_seq").desc())
latest = (merged
.withColumn("rn", F.row_number().over(w))
.filter(F.col("rn") == 1)
.drop("rn"))
latest.collect()
snapshot3 rows
listing_ref
price
change_seq
L1
100
3
L2
250
5
L3
80
2
changes5 rows
listing_ref
price
change_seq
L2
245
6
L2
240
7
L1
95
4
L2
240
7
L4
60
8
Preparing the animation

Window.partitionBy("listing_ref") hash-shuffles the union by key, so every version of L2 lands on 1 task whichever input it came from. That task sorts its rows by change_seq descending, and row_number keeps the first. The redelivered change gives 2 identical L2 rows at change_seq 7; either can take number 1 and the surviving row is the same. Feeding the output back in with the same changes returns the output unchanged.

Merges that converge

Keep latest by change_seq
changes appliedL2 price
once240
twice240
5 times240
Add +30 to a balance of 100
changes appliedbalance
once130
twice160
5 times250

A merge converges when applying a change twice equals applying it once. Keep-latest by sequence number has that property, and so does set union; max and min do too. Adding to a stored total lacks it: a balance updated with + 30 on every run drifts 30 higher per retry. For sums and counts, store the deduplicated events as the state and recompute the total from them, so a rerun recomputes a number instead of adding to one.

Multiple Choice

A daily job maintains each user's total spend from transactions, and the job for 2024-03-14 may run twice. Which design leaves the same result after 1 run or 2?

The ordering comes from the source

Keep-latest needs an ordering column that sorts the same way on every run. change_seq is assigned by the system that produced the change, so a replay sorts identically. A load timestamp stamped by your job is a poor substitute: a rerun stamps fresh times, and a redelivered old change can outrank a newer one that loaded first. When 2 versions can share an ordering value with different contents, add a second column to the ordering so exactly 1 row ranks first.

Run the cell. It applies keep-latest to the change log in listing_attribute_changes, ranking each listing attribute by change_seq and keeping rank 1. The op column records the kind of each change, and when the winning row is a delete, the attribute no longer exists, so the snapshot drops it instead of keeping its last value. Then change .desc() to .asc() and run again: the cell returns the earliest value still in the change log for each attribute, because the sort direction decides which version wins.

from pyspark.sql import functions as F
from pyspark.sql.window import Window

changes = spark.table("listing_attribute_changes")
w = Window.partitionBy("listing_ref", "attr_name").orderBy(F.col("change_seq").desc())

current = (changes
    .withColumn("rn", F.row_number().over(w))
    .filter(F.col("rn") == 1)
    .select("listing_ref", "attr_name", "attr_value", "change_seq", "op"))

current.orderBy("change_seq").show()
TIP
Keep the last week of snapshot directories. A bad merge is then repaired by fixing the code and rerunning from the last good ds, since every later snapshot is derived from it.

When the Driver Dies

Daily Life
Interviews
When an executor dies, Spark reruns its lost tasks from lineage and the job carries on. When the driver dies, the application ends. The driver is the single process that knows what the job is, and it keeps that knowledge in its own memory, where no successor can read it.
The driver holdsAfter it dies
The DAG, and which stages and tasks finishedGone: it lived only in driver memory
Which executor holds each shuffle blockGone, so no reducer can find its input
The executors' registrationsEach executor exits once it loses its driver
Cached partitions and broadcast variablesGone with the executors that held them
A running write's commit state`_temporary` stays on disk and no `_SUCCESS` is written
Temp views and session settingsGone with the session

A restarted driver is a rerun

Spark can relaunch a driver in cluster mode: on YARN the application gets up to spark.yarn.maxAppAttempts attempts, and the standalone manager relaunches drivers submitted with --supervise. Either way the new driver runs your program from its first line and builds a fresh DAG. The last attempt's shuffle output is gone, and so is any record of what that attempt finished. That's why the overwrite and upsert patterns above matter beyond manual reruns: they make an automatic relaunch safe.

Relaunches nobody asked for
spark.yarn.maxAppAttempts defaults to YARN's own limit, yarn.resourcemanager.am.max-attempts, which is 2 unless your cluster sets otherwise. A cluster-mode job whose driver runs out of memory therefore runs a second time with no one pressing rerun. A job that appends writes its output twice; a job that overwrites its partitions lands it once.

Resume by skipping finished chunks

The new driver remembers nothing, so whatever the job needs to remember has to live outside Spark: in durable outputs, plus a record of which ones are complete. Split a long job into chunks that each end in a committed write, such as 1 day or 1 month of a backfill, or 1 region. On start, the driver reads which chunks are done and runs only the rest.
days = ["2024-03-%02d" % d for d in range(1, 13)]
done = {r.load_date for r in spark.table("etl_control")
.filter("status = 'done'")
.select("load_date")
.collect()}
for day in days:
if day in done:
continue
build_day(day).write.mode("overwrite").parquet(f"/warehouse/payouts/ds={day}")
record_done(day)

The guarantee depends on the order of the last 2 lines. record_done runs only after write returns, and write returns only after job commit and _SUCCESS. If the driver dies between them, the day is written but unrecorded, and the next attempt rebuilds it with an overwrite that changes nothing. Swap the 2 lines and a crash can record a day that was never written, which every later attempt skips.

Take a backfill of 12 days that runs for 4 hours and whose driver runs out of memory partway through the last day.
3h 40m+
redone after the crash, as 1 job
20 min
redone at most, as 12 chunks
finished days
etl control
spark-submit
Driver loop
cluster modeRETRY1
Spark job
Build 1 day
IDEMPOTENCYoverwrite ds={day}
Parquet + _SUCCESS
payouts ds={day}
append to etl_control
Record done

The control table is read once at start, and each day is recorded only after its partition has committed.

Streaming resumes the same way

A Structured Streaming query survives a driver restart because its checkpoint directory has this pattern built in. Before a micro-batch runs, the driver writes the batch's offsets to the offset log, and after the sink finishes it adds an entry to the commit log. A new driver started with the same checkpointLocation finds the last batch with offsets and no commit, runs that batch again, and continues. A batch job gets the same recovery only when you write the control record and the idempotent chunk write yourself.

Multiple Choice

A job in cluster mode on YARN, with default settings, appends a result after each of its 6 hourly chunks. Its driver runs out of memory during chunk 5. What happens next?

Determinism on Replay

Daily Life
Interviews
Every recovery in this lesson replays work: Spark recomputes a lost partition, a relaunched driver reruns the program, a backfill rebuilds a day. Each replay assumes that evaluating the same expression on the same input gives the same rows. Some expressions break that assumption, and the failure is silent: the job succeeds and the numbers are wrong.

Expressions that change between evaluations

ExpressionWhat it depends onReplace it with
`F.rand()` after a shuffleRow order inside a partition, which a shuffle does not fixA hash of a stable key, such as `F.xxhash64("user_id")`
`F.current_date()`, `F.current_timestamp()`The clock when the run startsThe run's date, passed in as a parameter
`F.monotonically_increasing_id()`Partition index and row positionAn id from the source, or a hash of the natural key
`dropDuplicates(["event_uuid"])`Which copy reaches the task first`row_number()` over a complete ordering
`row_number()` ordered on a column with tiesArrival order among the tied rowsA unique column added to the ordering
`F.first("event_type")` in a `groupBy`Which row reaches the task first`F.max`, `F.min`, or a ranked pick
`limit(n)` with no `orderBy`Which rows reach the limit firstAn `orderBy` on a unique column before the limit

How a partial recompute corrupts a count

F.rand() fixes its seed when the query is planned and runs a generator per partition, so the value a row gets depends on its position in the partition. A file scan reads rows in the same order every time. A shuffle does not: a reducer fetches blocks from many map tasks in whatever order they arrive. Take a job that reads user_events, repartitions by user_id (shuffle 1), tags each row with F.when(F.rand() < 0.5, "A").otherwise("B"), and counts rows per bucket (shuffle 2). Map task 7 of the middle stage reads 10,000 rows and writes 2 partial counts. Its executor dies after the bucket A reducer has fetched them and before the bucket B reducer does. Spark reruns task 7, which fetches its rows again in a new order and draws new numbers.

Task 7's outputAttempt 1RecomputedUsed by the reducer
Bucket A5,0124,9915,012
Bucket B4,9885,0095,009
Total10,00010,00010,021
The job reports 10,021 rows from a task that read 10,000. The Spark UI shows a fetch failure and a stage retry, the same as for any lost executor, and every task finishes successfully.
TIP
Spark guards 1 case itself: before repartition(n) deals rows out round-robin, it sorts them within each partition (spark.sql.execution.sortBeforeRepartition, true by default), so a retried map task sends each row to the reducer it went to before. An expression you write, such as rand(), gets no such check.

Reruns need a fixed clock

F.current_date() is fixed once per query, so every row of a run agrees. The trouble is the next run. A job that processes F.date_sub(F.current_date(), 1) and runs on 2024-03-15 handles March 14. Rerun it on 2024-03-16 to repair March 14 and it processes March 15 instead and overwrites that partition. The job reports success while March 14 stays broken. Pass the date the run is for as a parameter, like the run_day of the overwrite section, and a rerun reads and writes the same day whenever it happens.

Multiple Choice

This job is rerun on the same input for the same run_day. Which expression can make the rerun write different rows?

events = spark.table("user_events")
daily = (events
.filter(F.col("event_date") == run_day)
.withColumn("sample", F.xxhash64("user_id") % 10 == 0)
.groupBy("country", "sample")
.agg(F.countDistinct("user_id").alias("users"),
F.first("event_type").alias("example_event")))

Deduplicate with a complete ordering

The same event_uuid can appear on several rows of app_event_deliveries, 1 per delivery, with different received_ts values. dropDuplicates(["event_uuid"]) keeps 1 row per event, but which row depends on which copy reached the task first after the shuffle, so a rerun can keep a different received_ts and move an event into a different hour. Ranking by received_ts and then delivery_id gives every pair of rows a strict order, so rank 1 is the same row on every run. Run the cell. Then delete F.col("delivery_id").asc() from the ordering and work out whether 2 deliveries with equal received_ts could still trade places.

from pyspark.sql import functions as F
from pyspark.sql.window import Window

deliveries = spark.table("app_event_deliveries")
w = Window.partitionBy("event_uuid").orderBy(
    F.col("received_ts").asc(), F.col("delivery_id").asc())

firsts = (deliveries
    .withColumn("rn", F.row_number().over(w))
    .filter(F.col("rn") == 1)
    .drop("rn"))

firsts.orderBy("delivery_id").show()
✓Do
  • Pass the date a run is for into the job as a parameter
  • End every ranking order with a unique column, such as delivery_id
  • Build sample buckets and synthetic ids from a hash of a stable key
  • Pick 1 row per group with max or min, or with a row_number over a full ordering
✗Don't
  • Read current_date() in a job that may be rerun on a later day
  • Feed rand() computed after a shuffle into a later shuffle
  • Count on dropDuplicates or first() to choose a particular row
  • Join other tables on monotonically_increasing_id()
Multiple Choice

This job keeps 1 delivery per event_uuid from app_event_deliveries. Two deliveries of one event share the received_ts 2024-03-14 09:00:00 and carry different delivery_id values. Which change to the window keeps the same delivery on every rerun?

from pyspark.sql import functions as F
from pyspark.sql.window import Window
w = Window.partitionBy("event_uuid").orderBy(F.col("received_ts").asc())
firsts = (spark.table("app_event_deliveries")
.withColumn("rn", F.row_number().over(w))
.filter(F.col("rn") == 1)
.drop("rn"))
❯❯❯PUTTING IT ALL TOGETHER

> Picture the Airbnb host payouts job from the intro, now backfilling 12 days after a currency bug. It runs in cluster mode on YARN, builds 1 day per chunk from immutable booking changes, and writes a payouts table partitioned by ds. On day 9 the driver runs out of memory, and YARN relaunches it.

The relaunched driver reads its control table, skips days 1 to 8 and rebuilds day 9, because each day was recorded only after its write returned.
Day 9's interrupted write left _temporary and no _SUCCESS, so the finance job waiting on the marker never read it.
Each day is written with dynamic overwrite or to its own ds path, so rebuilding day 9 replaces that day and leaves days 1 to 8 as they were.
Booking changes are merged by keeping the latest version per reservation by the source's sequence number, so a redelivered change cannot double a payout.
The day being processed comes from a parameter and any sampling from a hash of the host id, so the relaunched driver computes the same rows the first attempt would have.
KEY TAKEAWAYS
A write publishes through the committer: tasks write under _temporary, the driver grants 1 commit per partition, renames the files into place and writes _SUCCESS last.
Readers should wait for _SUCCESS. Job commit renames files 1 by 1, so a directory without the marker can hold part of a job.
append duplicates on every rerun, static overwrite with partitionBy deletes every other partition, and dynamic overwrite replaces only the partitions the job wrote rows for.
An upsert in plain files is a rebuild: yesterday's snapshot plus today's changes, latest per key by a source sequence number, written to a new directory.
When a driver dies, the DAG and shuffle locations die with it, and so do its executors. Any relaunch is a rerun, so resumable jobs commit in chunks and record each chunk after its commit.
Replays assume determinism. rand() after a shuffle can make a recompute or rerun produce different rows, and so can reading the clock; first() and dropDuplicates do the same, as do orderings with ties.

How a Spark write publishes all or nothing, and how to build jobs that rerun, resume and replay to the same result.

Category
Spark
Difficulty
intermediate
Duration
14 minutes
Challenges
17 hands-on challenges

Topics covered: Atomic Writes, Overwrite vs Append, Idempotent Upserts, When the Driver Dies, Determinism on Replay

Lesson Sections

  1. Atomic Writes (concepts: Distributed Primitives)

    Writing a 1,000-partition DataFrame runs 1,000 tasks, and each task writes its own Parquet file. Those tasks finish minutes apart and some of them fail and run again. The job itself can die at any moment. If every task wrote straight into the destination, a reader polling it would see 400 files at 02:01 and 700 at 02:03. A crash would leave a table that is 70% complete and looks finished, and a retried task could leave 2 copies of the same part file. Spark prevents all 3 problems with a commit p

  2. Overwrite vs Append (concepts: Caching & Persistence)

    Overwrite deletes more than the day Dynamic mode replaces the days you wrote When the fixed day has no rows Dynamic mode replaces only partitions that receive rows. Suppose 2024-03-14 was loaded from a corrupt file and the fixed rerun filters out every row. The job writes nothing for that day, so nothing is replaced, and the corrupt partition outlives a run that reported success. When a day must equal the job's output even if that output is empty, write to the partition's path:

  3. Idempotent Upserts (concepts: Keyed Deduplication)

    Day partitions work when every row belongs to the day it arrived. A listings table breaks that: it holds 1 row per listing, and a listing created on March 2 can change price on March 14 and again on March 15. No day owns that row, so appending each day's changes leaves 3 versions of it, and overwriting a day keeps only the listings that changed that day. The table needs an upsert: insert new keys and update existing ones. Rebuild from inputs that never change The animation runs that merge on a s

  4. When the Driver Dies (concepts: Caching & Persistence)

    When an executor dies, Spark reruns its lost tasks from lineage and the job carries on. When the driver dies, the application ends. The driver is the single process that knows what the job is, and it keeps that knowledge in its own memory, where no successor can read it. A restarted driver is a rerun Resume by skipping finished chunks The new driver remembers nothing, so whatever the job needs to remember has to live outside Spark: in durable outputs, plus a record of which ones are complete. Sp

  5. Determinism on Replay (concepts: Distributed Primitives)

    Every recovery in this lesson replays work: Spark recomputes a lost partition, a relaunched driver reruns the program, a backfill rebuilds a day. Each replay assumes that evaluating the same expression on the same input gives the same rows. Some expressions break that assumption, and the failure is silent: the job succeeds and the numbers are wrong. Expressions that change between evaluations How a partial recompute corrupts a count The job reports 10,021 rows from a task that read 10,000. The S