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.

The range expands into 90 runs, one per logical date. Each run replaces its own partition, and 8 runs execute at a time.
  • 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 pipelineWhat the 90-day backfill leaves behind
Appends instead of replacingEvery day holds the old inflated rows plus the corrected rows, more than twice the true revenue
Filters relative to the clockEach run reads the 24 hours before its start, so 90 partitions hold overlapping recent slices
Merges on a `uuid()` keyEvery row is inserted again under a new key, next to its old copy
DELETE and INSERT filters disagreeRows the delete misses survive, so old values linger beside new values
Idempotent writes, explicit time bounds, unique keysEach 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?

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:

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?

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.