Skip to the page

Orchestration and dbt · core

Idempotent loads, reruns and backfills

A task that can run twice with the same result is idempotent. Use the run's own date, not the wall clock, and overwrite or merge instead of appending, so retries and backfills are safe.

The notes

What you must know

  • datetime.now() ties the data to the wall clock: a retry after midnight, a manual rerun or a backfill loads yesterday relative to now. Use the run's logical date or data interval, in the business time zone (IST).
  • INSERT INTO appends. If the insert commits and a later step fails, the retry inserts again. Make it idempotent: delete that day and insert in one transaction, MERGE on the key, or overwrite the partition.
  • Two statements with no transaction can leave a half-done state. Use one transaction, or read state from the data instead of a log table.
  • List columns instead of SELECT *, use bind parameters instead of f-strings for SQL, and filter on the partition column rather than CAST(created_at AS DATE).
  • Set retry_delay and execution_timeout. Setting retries to 0 or hiding duplicates with DISTINCT downstream is not a fix.
  • Backfill preconditions: every task takes its date from the run (not CURRENT_DATE or now), the source data still exists (a lake keeps months; Kafka's default retention is much shorter), and dimension history exists as of each day (SCD type 2).
  • Write backfill output to a new table, compare, then switch a view or rename, so live numbers never change halfway.
  • Airflow 3 runs backfills inside the scheduler (UI or airflow backfill create) with a cap on active runs. A single set-based query over the whole range is often cheaper than one run per day.
  • Protect the daily run: a small max_active_runs for the backfill, a separate pool and priority, a separate warehouse. Estimate cost as one day's cost times the number of days.
  • Validate: old and new definitions side by side for a few days, totals, spot checks, and a note on the dashboard about the change and its date.

The red pen

Common traps: mistake → fix

  • Mistake: Rerun the DAG 180 times for a backfill

    Fix: first check that no task uses CURRENT_DATE.

  • Mistake: Fix duplicates with DISTINCT in the dashboard

    Fix: fix the append in the load.

  • Mistake: Overwrite live tables directly during a backfill

    Fix: write a new table and switch.

Easy to hard

Questions interviewers ask, easy to hard

  1. This daily load creates duplicates after retries. What is wrong?
  2. What does idempotent mean for a pipeline task?
  3. Product changed a metric definition. How do you backfill six months?
  4. How do you protect the daily run during a backfill?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview