The Backfill Operation
A backfill runs the pipeline for a range of past logical dates. Two reasons start most backfills: a gap where runs never happened, and a logic fix that makes past output wrong. Take the second. A currency conversion bug inflated agg_daily_revenue for every day from 2026-01-01 through 2026-03-31. After the fix ships, those 90 logical dates have to run again with the corrected code.
- Backfill range (source, 2026-01-01 to 2026-03-31)
- Run per ds (transform, Orchestrator); parallelism: 8 runs; backfill: one run per logical date; idempotency: partition overwrite
- agg_daily_revenue (storage, Partitioned by ds)
- Revenue dashboard (consumer, Finance)
- Backfill range -> Run per ds
- Run per ds -> agg_daily_revenue
- agg_daily_revenue -> Revenue dashboard
from datetime import date, timedelta
start = date(2026, 1, 1)
end = date(2026, 3, 31)
ds = start
while ds <= end:
run_pipeline(ds=ds.isoformat())
ds += timedelta(days=1)Why only idempotent pipelines survive it
All 90 partitions already hold data from runs that succeeded. A backfill is therefore 90 reruns at once, and every flaw a single retry would expose shows up 90 times. Each earlier section of this lesson predicts a failure.
| Flaw in the pipeline | What the 90-day backfill leaves behind |
|---|---|
| Appends instead of replacing | Every day holds the old inflated rows plus the corrected rows, more than twice the true revenue |
| Filters relative to the clock | Each run reads the 24 hours before its start, so 90 partitions hold overlapping recent slices |
| Merges on a `uuid()` key | Every row is inserted again under a new key, next to its old copy |
| DELETE and INSERT filters disagree | Rows the delete misses survive, so old values linger beside new values |
| Idempotent writes, explicit time bounds, unique keys | Each partition is replaced with its corrected contents, and nothing else changes |
A pipeline reads the 24 hours before current_timestamp and writes into its run's ds partition by partition overwrite. In June, it backfills 2026-01-01 to 2026-03-31. What do the 90 partitions hold afterwards?
- Corrected data, since partition overwrite makes reruns safe
- Recent June bookings in overlapping slices, under 90 dates
- Their old data with the June bookings appended
- No rows, since a June run finds no January bookings
Order and parallelism
When each run reads only its own day's inputs and writes only its own partition, the 90 runs are independent. They can run in any order and several at once, limited by the cluster and by the source systems they read. Some runs read the previous day's output, as a running total, a cumulative guest count or a first-booking flag does. Then day N needs day N-1 finished and corrected first. Those runs go one at a time, oldest first, and a single failure stops everything after it.
At 12 minutes per run, the 2 approaches finish at very different times:
- 18 h
- 2 h 24 m
Before starting the range
guest_lifetime_value for day N adds day N's spend to the value stored for day N-1. You backfill January after a fix. How should the 31 runs execute?
- 8 at a time in any order, since each run writes its own partition
- Newest first, so that recent values are corrected soonest
- All 31 at once, then a second pass to repair any mistakes
- A run at a time from January 1, each after the previous one succeeds
About this lesson
This section is part of the Idempotent Reruns: Intermediate lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.