Problem
Batch jobs fail midway, are retried by schedulers, or are rerun by operators. If each run appends or mutates blindly, duplicates and partial writes corrupt the output.
Also known as: rerunnable-jobs, safe-retry-batch
Make batch jobs produce the same result when run multiple times so retries and reruns are safe.
Batch jobs fail midway, are retried by schedulers, or are rerun by operators. If each run appends or mutates blindly, duplicates and partial writes corrupt the output.
A job is idempotent if running it once or many times with the same inputs leaves the same final state. For batch pipelines this converts failure handling into a single rule: just run it again.
The two main techniques are partition overwrite and keyed merge, combined with atomic publish.
run(date = D):
input = raw.events where event_date = D # fixed snapshot
out = transform(input) # pure function
write out to staging/D/
atomically replace curated/event_date=D with staging/D
With a table format that supports transactions, use a single statement:
INSERT OVERWRITE TABLE curated.daily_sales PARTITION (sale_date = :d)
SELECT ... FROM raw.sales WHERE sale_date = :d;
For upserts, MERGE on the primary key so replays update instead of insert. A run is identified by its logical date, not the time it started, so a retry at noon for yesterday's data processes yesterday's data. Success markers, such as a manifest file written last, let consumers wait for complete partitions.
Low - mostly design discipline
Low - fewer manual repairs
Low - concept is simple
Append-only write duplicates rows on retry
Readers see partially written output
Job reads mutable current state so reruns differ