Skip to content

Lesson 5 of 9 · 27m

Incremental State, Late Data, and Backfills

Manage checkpoints honestly, handle late-arriving facts, and make backfills first-class operations instead of emergency rituals.

Incremental pipelines fail in quiet ways. They do not crash; they skip. A watermark moves too far, a source API paginates inconsistently, or a correction arrives after the window closes. Months later someone asks why revenue changed retroactively and the team discovers that the pipeline optimized for efficiency by forgetting history. State is the price of incremental speed. Treat it as a correctness mechanism, not as bookkeeping.

Know what your watermark means

A watermark is a promise: "I believe events before this time are complete enough to process." That promise can be input-driven, time-driven, or purely operational convenience.

high_watermark = query_max_updated_at(source)
rows = extract_where("updated_at > %s AND updated_at <= %s", [last, high_watermark])
write_rows(rows)
if write_succeeded:
    save_checkpoint(high_watermark)

The order matters. Save the checkpoint only after the write commits. Yet even this pattern misses rows whose timestamps move backward, transactions not visible during extraction, and clock skew across systems.

Late data is normal data

Mobile events, offline systems, batch-uploaded partner files, and slowly closing business transactions all arrive late. Decide explicitly how late is meaningful:

operational metrics       accept late data for 1 hour
product analytics         restate partitions for 7 days
finance ledger            corrections forever, but controlled adjustment entries
ML training features      fixed snapshot unless retraining requires restatement

Backfills are normal operations

A backfill should be parameterized, isolated, observable, and rate-limited:

python -m pipelines.orders --start-date 2026-02-01 --end-date 2026-02-29 --write-mode replace-partition --max-concurrency 2 --validate

If backfill requires editing code, manually deleting partitions, and muttering prayers over production credentials, the design is incomplete. Test backfill on a small historical range before you need it during an incident.

Mutable business entities break naive incrementality

Orders get canceled. Customer records merge. Refunds alter old facts. Dimension tables overwrite state. When input is mutable, incremental extraction by updated_at captures change events but does not automatically reconstruct correct history. You may need change data capture, snapshots, slowly changing dimensions, or periodic reconciliation.

SELECT order_id, status, updated_at
FROM source_orders
WHERE updated_at >= TIMESTAMP '2026-03-14 00:00:00'
  AND updated_at <  TIMESTAMP '2026-03-15 00:00:00';

That query tells you what changed, not whether every related aggregate is now correct. Downstream partitions may still need restatement.

Reprocessing strategy beats dogma

Full refresh is expensive but simple. Pure incremental is efficient but error-prone. Most mature systems use a hybrid: incremental daily processing plus scheduled lookback restatement and rare full rebuilds. For example, process yesterday incrementally, restate the trailing seven days nightly, and reconcile monthly.

Field notes

  • Never advance a checkpoint before durable output commits; crashing between write and checkpoint is normal, not hypothetical.
  • Overlapping windows are cheaper than missing data. A five-minute overlap plus deduplication often beats a perfect boundary.
  • Record source query boundaries in run metadata. During disputes, exact input windows matter more than task logs.
  • Backfills can overload production sources. Use replicas, lower concurrency, and communicate before replaying months of history.

Was this lesson helpful?

Sign in to rate