Worked design: daily batch with backfills
This is the most common design question for junior and mid candidates, and the most common source of real incidents. The goal is one property: any day can be re-run at any time and give the same, correct result.
A daily batch pipeline that can be backfilled safely
Every day at 02:00 a pipeline loads yesterday's orders from an API and a vendor SFTP drop, transforms them, and publishes daily_revenue for an 07:00 executive dashboard.
Last month a bug in the transform went unnoticed for 9 days, and fixing it took a week of manual reruns. Design the pipeline so that reruns and backfills of any date range are boring.
Hint 1
What does running the same day twice do to the output?
Hint 2
How do you rerun 90 days without overloading the API or blocking today's run?
Show solution
Orchestrate with Airflow/Dagster, one run per logical date. Each task is a pure function of that date: extract only that date's window into a raw path that includes the date (raw/orders/dt=2024-05-01/), transform, and overwrite the output partition for that date. Never append. This makes every run idempotent: running a day twice gives the same result.
Backfills are just runs for past logical dates with limited concurrency (pools), lower priority than the daily run, and a rate limit on the source API. Prefer re-transforming from stored raw data, so the API isn't hit again. Publish via a write-audit-publish pattern: build into staging, run data quality checks (row counts versus source, revenue versus the previous day, nulls, duplicates), and swap or overwrite only if they pass, so the 07:00 dashboard never shows a half-loaded or broken day.
Add an SLA alert at 06:00, lineage so you know which downstream tables a backfill must touch, and a "data as of" note on the dashboard.
What a strong answer covers
- Parameterizes everything by logical date (no "now()" inside tasks) (weight 3)
- Idempotent writes: overwrite the partition for that date, never blind append (weight 3)
- Keeps raw extracts so backfills re-transform without re-extracting (weight 2)
- Backfill throttling: concurrency limits, priority below the daily run, source rate limits (weight 2)
- Quality gate before publishing (write-audit-publish) and SLA alerting (weight 2)
Follow-ups
- The transform depends on a dimension that has changed since then. Should a backfill use today's dimension or the historical one?
Usually the historical version, so a backfill reproduces what the data meant at that time: join to an SCD2 dimension as of the event date. Use today's version only when the business explicitly wants restated history (for example a current org structure). Either way, decide it deliberately and document it.
- How do you backfill a table that 30 downstream dbt models depend on?
Backfill the upstream table in date-range batches, then rebuild downstream with lineage-aware selection (
dbt build --select table+) for the same partitions. Schedule it outside the daily run's window, consider writing to a separate schema and swapping it in, and validate row counts before releasing.
Further reading
1. Requirements
- Sources: an orders API (paginated, rate-limited) and a vendor file on SFTP, both for "yesterday".
- Schedule: start 02:00; dashboard reads at 07:00.
- Correctness: executive revenue, so wrong is worse than late.
- History: reruns of any range, from one day to a year.
2. Data contracts
The API supports filtering by updated_at and returns stable IDs. The vendor promises one file per day, named with the date, by 01:30. Write down what "yesterday" means (which time zone) before anything else. It's the most common silent bug in daily pipelines.
3. Ingestion
Each task takes a logical date ds as input, never "now":
extract_api(ds) → raw/orders_api/dt=ds/part-*.json
extract_vendor(ds) → raw/vendor/dt=ds/file.csv
Extraction pulls exactly the window for ds and writes it to a path that includes ds. Re-running overwrites that path.
4. Storage and format
Keep raw extracts for at least as long as you might backfill (for example 13 months). They're cheap, and they let you re-transform without hitting the API again. Modeled tables are partitioned by ds.
5. Transform
transform(ds) reads only raw/*/dt=ds, plus dimensions, and overwrites partition ds of fct_orders and daily_revenue. Never append. An append makes a re-run double the day.
Historical or current dimensions in a backfill? It depends on the question. "Revenue by the region the customer had then" needs the dimension version valid on ds (SCD2). "Revenue by current region" uses today's. Decide per model and write it down.
6. Serving
The dashboard reads daily_revenue and shows "data as of" from a small metadata table updated at publish time.
7. Quality: write-audit-publish
- Write to a staging location (
daily_revenue__stagingpartitionds). - Audit: row count versus the source, revenue within a band of the trailing 7-day average, no NULL keys, no duplicate order IDs, the vendor total ties to the vendor file's trailer.
- Publish: swap or overwrite the production partition only if every check passes. Otherwise alert, and keep showing yesterday's published data with a banner.
8. Orchestration and backfill
- In Airflow or Dagster, one DAG run per
ds, withcatchupfor missed days. Tasks are idempotent, so retries are safe. - Backfill a range with the same DAG:
backfill --start 2024-03-01 --end 2024-05-31. Put backfill runs in a pool with limited concurrency and lower priority than the daily run, and respect the API's rate limit. Re-transform from raw where possible. - Use lineage (dbt's graph or the orchestrator's asset graph) to find every downstream table that must be rebuilt for the backfilled range, and run them in dependency order.
9. Failure modes
| Failure | Detection | Recovery |
|---|---|---|
| Vendor file late | Sensor timeout at 05:00 | Alert vendor contact; publish API part with "partial" flag if agreed |
| API returns partial data | Row-count check vs API's reported total | Retry extract for ds |
| Bug found 9 days later | Someone notices | Fix, backfill 9 days from raw, downstream via lineage, done in an hour |
Job uses now() instead of ds | Backfilled days all get today's data | Code review rule plus a test that runs one historical ds |
| Time zone mismatch | Revenue shifts between days | One agreed reporting time zone in the contract; test around midnight |
10. Cost
Re-transforming from raw is usually cheaper than re-extracting. Partition pruning keeps each daily run proportional to one day, not the whole table.
11. What changes at 10×
If one day takes too long, split ds into hours, or process incrementally by updated_at within the day with a final daily reconciliation. The idempotency rules stay the same.