Make an Airflow backfill repeatable
A Tuesday retry runs on Thursday. The task writes rows for the system date and the scheduled Tuesday partition is still incomplete. Which input should drive publication?
Make an Airflow backfill repeatable
A pipeline needs to answer which interval it is processing and what to do if the previous attempt partly succeeded. Pass a fixed data interval to each task. Treat the publish operation as a named commit point and delay downstream release until that commit succeeds.
In the recording
Pass the logical date into Airflow tasks and replace that date’s output partition on a retry or backfill.
Work through the decision
A Tuesday retry runs on Thursday. The task writes rows for the system date and the scheduled Tuesday partition is still incomplete. Which input should drive publication?
Check your reasoning
Use the logical data interval supplied by the scheduler. Scope reads and writes to that interval and make replacement atomic or merge by stable keys. A dependency should release downstream consumers only after the interval passes its checks.
Decisions and tradeoffs
- Logical interval
- Use the scheduled interval to choose input and destination partitions. A retry or backfill then targets the original period.
- Idempotent write
- Replaying the same accepted input produces the same sink state. Replace a bounded partition atomically or merge on a stable business key.
- Dependency edge
- Express which upstream tasks must succeed before validation and publication can run.
- Bounded retry policy
- Limit retry attempts and apply a delay for a transient failure. Escalate persistent data or configuration problems.
Carry the publication boundary into BigQuery
For a complete daily snapshot, first stage and reconcile the chosen interval. In the example below, @run_day is a DATE parameter. The target and staging tables are assumed to share the displayed columns. Use an isolated practice dataset for this pattern.
BEGIN TRANSACTION;
DELETE FROM study.daily_totals WHERE day = @run_day;
INSERT INTO study.daily_totals (day, depot, units)
SELECT day, depot, SUM(units)
FROM study.accepted_events
WHERE day = @run_day
GROUP BY day, depot;
COMMIT TRANSACTION;Readers see the committed result as a unit. Before publication, verify the input interval is complete and has the expected event keys. An atomic replacement of an incomplete source can still publish an incorrect total.
Practice the guide skills
- Draw a DAG with independent loads, a join, a quality gate and one publish task.
- Run a retry and a backfill against fixed intervals and compare row-level outputs.
Official objectives for this lesson
Rebuild a daily partition twice
Save this exercise as replay.py and run it with Python 3. It uses an in-memory SQLite database. Predict how many rows the second run writes to the final result and which existing day survives. Compare the output before changing the interval.
import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE totals(day TEXT PRIMARY KEY, units INTEGER)")
db.execute("INSERT INTO totals VALUES ('2026-03-01', 9)")
source = [("2026-03-02", 4), ("2026-03-02", 7), ("2026-03-03", 2)]
def publish(day):
total = sum(units for record_day, units in source if record_day == day)
with db:
db.execute("DELETE FROM totals WHERE day = ?", (day,))
db.execute("INSERT INTO totals VALUES (?, ?)", (day, total))
for attempt in range(2):
publish("2026-03-02")
print(list(db.execute("SELECT * FROM totals ORDER BY day")))
Check the result
[('2026-03-01', 9), ('2026-03-02', 11)]
[('2026-03-01', 9), ('2026-03-02', 11)]Both attempts commit the same partition contents, and March 1 stays at 9. Append a legitimate March 2 correction worth 3 and publish that day again. Expect 14. Change the second call to March 3 to confirm it adds a separate partition worth 2. In BigQuery, apply the same bounded-write contract with a transaction or an appropriate MERGE.
Related lesson · Choose the transformation engine and its data contract
Make an Airflow backfill repeatable quiz
Answer 3 questions. Check each answer for an explanation.