Data Engineering for AnalyticsVol. 21 · Analytics
0 / 0

Shelves / Data Engineering for Analytics

DE·05

Orchestration and Backfills

Running pipelines reliably on a schedule: DAGs of tasks or data assets, dependencies and data intervals, why every task must be idempotent and parameterised by the period it processes, retries, timeouts and alerts, backfills and catch-up, sensors and data-aware scheduling, concurrency limits, and how Airflow, Dagster and Prefect approach it; with a lab in which a 30-day backfill with flaky workers inflates orders by 53% when tasks append, and lands exactly when they overwrite their partition.

17 topics · ~8 min read · 16-question quiz
Updated Suggest a correction

Start here: pipelines fail, and then they run again

TiffinBox's analytics run every night: load yesterday's orders and payments, rebuild the dbt models, refresh dashboards, export features for the assistant. Each step depends on others, any step can fail (a source is late, a worker dies, a quota is hit), and failed steps are run again: automatically by retries, or by an engineer next morning, or as part of a backfill that reprocesses months of history after a bug fix.

An orchestrator runs this: it knows the graph of tasks (a DAG: directed acyclic graph), when each should run, what it depends on, and what to do when it fails. But the orchestrator can't make a task safe to run twice. That's the task author's job, and it's the central lesson of this chapter.

What a retry does to a non-idempotent task

The lab backfilled 30 daily partitions of a summary table, with workers that "died" after writing but before reporting success 30% of the time (so the orchestrator retried them, up to 3 attempts):

Task writes by… Attempts Orders in the table Error
appending rows for the day 46 504,066 +53%; revenue off by ₹4.2 crore
replacing the day's partition in one transaction 46 328,753 exact

Same orchestrator, same failures; the only difference was whether running a task twice had the same effect as running it once.

How deep to go

Volume 17 defines six mastery levels. For orchestration:

Level What you can do
L1 Explain DAGs, schedules, retries and backfills
L2 Write and schedule pipelines in an orchestrator
L3 Explain data intervals, idempotency, data-aware scheduling and concurrency limits
L4 Debug stuck runs, duplicates after retries, and backfill side effects
L5 Design a pipeline platform: conventions, partitioning, SLAs, ownership
L6 Operate it: upgrades, scaling workers, incident response, cost

DAGs, tasks and assets

Two ways to describe pipelines:

  • Task-centric (Airflow): a DAG of tasks (load orders → build dbt models → refresh dashboards), each an operator running something somewhere.
  • Asset-centric (Dagster; increasingly Airflow too): you declare the data assets (tables, files, models) and how each is computed from others; the orchestrator derives the graph, knows which assets are stale, and can materialise just what's needed.

Either way, keep tasks coarse enough to be meaningful units of retry (load one source for one day; run one dbt selection) and fine enough that a failure doesn't redo hours of unrelated work.

Data intervals and partitions

Every run processes a period: Airflow passes the data interval (data_interval_start, data_interval_end); Dagster passes a partition key (2026-11-04). The task uses those, never the clock:

Python
# wrong: depends on when it runs
day = date.today() - timedelta(days=1)
# right: depends on the period the orchestrator assigns
day = context.partition_key   # or data_interval_start in Airflow

Partition outputs by the same period (a date partition in a table or a directory per day), so each run owns one partition.

Idempotency: the rule

Pattern Idempotent?
INSERT INTO daily SELECT … WHERE day = :day no: a rerun appends again (the lab: +53%)
DELETE WHERE day = :day; INSERT … in one transaction yes
INSERT OVERWRITE PARTITION (day = :day) / dynamic partition overwrite yes
MERGE on a natural key yes
writing a file to …/day=2026-11-04/part-0.parquet (same name each run) yes, if the directory is cleared or files are replaced atomically
sending emails, calling external APIs no: guard with a record of what was sent (chapter 211E of Volume 19)

Also make reads deterministic: read the period's partition (or a snapshot of the source), not "all rows newer than the last run", unless that watermark is itself stored and advanced transactionally.

Retries, timeouts and alerts

  • Retries with back-off for transient failures (network, quotas); a small number (2–3); and only on idempotent tasks.
  • Timeouts per task, so a hung query doesn't block the whole pipeline for hours.
  • SLAs / freshness expectations: "fct_orders for yesterday by 06:00"; alert when missed, not just when a task fails (a pipeline that never started fails silently).
  • Alerts with context: the task, the period, the error, a link to logs, and the owner; route to the team that owns the data.

Backfills and catch-up

A backfill reruns tasks for a range of past periods: after fixing a bug, adding a model, or recovering from an outage. Catch-up is the orchestrator automatically running periods it missed while it was down (often disabled by default; enable deliberately).

Before a backfill:

  1. Confirm every task in the range is idempotent (the lab).
  2. Limit concurrency (pools) so you don't hammer source databases or exhaust warehouse quotas.
  3. Decide the order (oldest first, so cumulative models build correctly) and whether downstream consumers should see partial results.
  4. Estimate cost (a year of daily reruns of an expensive model).
  5. Mark the backfill in dashboards' annotations so people know numbers are changing.

Sensors and data-aware scheduling

Time-based schedules assume inputs are ready at 02:00. When they aren't, tasks either fail or, worse, succeed on incomplete data. Better:

  • Sensors wait for a condition (a partition exists, a source's freshness timestamp passes, a file lands), with timeouts.
  • Data-aware scheduling triggers downstream work when upstream assets update (Airflow assets/datasets, Dagster's declarative automation), so late sources delay rather than corrupt.
  • Completeness checks before publishing: row counts within expected ranges, all sources loaded for the period (chapter 08).

Choosing an orchestrator

Tool Model Strengths
Apache Airflow task DAGs in Python, with asset-aware scheduling in recent versions ubiquitous, huge operator ecosystem, managed offerings
Dagster software-defined assets, partitions, lineage, built-in data quality checks strong developer experience for data assets, testing
Prefect Python flows with dynamic tasks lightweight, flexible
dbt Cloud / warehouse schedulers scheduled dbt jobs or SQL simplest when everything is SQL in one warehouse
Kubernetes CronJobs containers on a schedule fine for a handful of independent jobs; no lineage or backfills

Start with what your team can operate; the concepts in this chapter matter more than the brand.

TiffinBox's nightly pipeline

Text
[sensor: PostgreSQL CDC for day D complete] ─┐
[sensor: payment-provider settlement file]   ├─→ load raw (D) ─→ dbt build (staging, marts for D) ─→ quality checks ─→ publish (refresh BI extracts)
[sensor: Kafka events to object storage]     ─┘                                                  └─→ export assistant features
every task parameterised by D; every write replaces D's partition; retries ×2; SLA: marts for D by 06:00 IST

Common traps

  • now() inside tasks.
  • Appending writes with retries enabled.
  • Uncapped backfills that take down a source database.
  • Alerting only on failure, not on missed freshness.
  • Heavy processing inside the orchestrator's workers.

Lab: a backfill with flaky workers

Setup. DuckDB on the lab machine; chapter 01's 5 million orders as the source. A minimal "orchestrator" in Python backfills a table daily(order_date, kitchen_id, orders, revenue) for 30 days (September 2026), one task per day. Each task runs its write in a transaction; after a successful commit, the worker "dies" with probability 0.3 before reporting success (a lost heartbeat, an evicted pod), so the orchestrator retries the task, up to 3 attempts. The random seed is the same for both modes, so both see exactly the same failures.

Two task implementations:

  • append: INSERT INTO daily SELECT … WHERE placed_at in day D.
  • overwrite: DELETE FROM daily WHERE order_date = D; INSERT … in the same transaction.

Results

Mode Attempts Writes followed by a "failure" Orders in table True orders Revenue error
append 46 18 504,066 328,753 +₹4,20,66,831 (+53%)
overwrite 46 18 328,753 328,753 ₹0

What it shows

  • Retries assume idempotency. Every "failure after the write" became a duplicate day in append mode; the orchestrator did exactly what it should.
  • The failure mode is invisible: no errors, plausible numbers, and a table that was 53% too large.
  • Replacing the partition in one transaction made the task safe to rerun any number of times, which also makes backfills and manual reruns safe.
  • In a real platform the same applies to dbt incremental strategies, Spark's partition overwrite mode, and any task that loads files.

Try it yourself

  1. Rewrite the task with MERGE (or INSERT … ON CONFLICT DO UPDATE in PostgreSQL) on (order_date, kitchen_id) and rerun.
  2. Run the 30 tasks with 4 in parallel and add a pool limit of 2; measure the source's load.
  3. Build the same backfill as a Dagster daily-partitioned asset (or an Airflow DAG with catchup=True) and inject the same failures.
  4. Make the task read "orders since the last run" from a stored watermark, and find the bug when a retry happens after the watermark was advanced.

Revision sheet: orchestration and backfills

Key ideas

  • Orchestrators run DAGs of tasks or assets on schedules or data events, with retries, timeouts and alerts.
  • Tasks process the period they're given, never the clock.
  • Every task idempotent: replace partitions, delete+insert, merge; deterministic reads.
  • Retries only for idempotent tasks; SLAs on freshness, not just failures.
  • Backfills: idempotency, concurrency limits, order, cost, communication.
  • Sensors and data-aware scheduling stop late inputs from producing wrong outputs.
  • The orchestrator schedules; the warehouse, Spark or containers compute.

Numbers to remember

  • Lab: 30-day backfill, 30% post-write failures: append +53% orders; overwrite exact.

Glossary

  • DAG: directed acyclic graph of tasks.
  • Data interval / partition key: the period a run processes.
  • Backfill: rerunning past periods.
  • Catch-up: automatically running missed intervals.
  • Sensor: a task that waits for an external condition.