Every pipeline eventually fails halfway: an API times out, a server restarts, a file arrives late. Someone re-runs it. The question is whether the re-run fixes things or quietly doubles yesterday's revenue.

A pipeline is idempotent when running it twice for the same input gives the same result as running it once.

Process in fixed windows

Give every run a clear slice of data, usually a date or hour: "load orders for 2026-10-28". Avoid "load everything since last time", because "last time" changes when a run fails.

Replace, don't append

For each window, overwrite that window's output instead of adding rows to it:

DELETE FROM daily_sales WHERE sale_date = '2026-10-28';
INSERT INTO daily_sales SELECT ... WHERE sale_date = '2026-10-28';

Run both statements in one transaction, or write to a partition and swap it in, so readers never see a half-loaded day.

Upsert on natural keys

When records arrive individually, use a key that identifies the real-world thing (an order ID, not an auto-increment) and upsert on it. A duplicate delivery then updates the row instead of adding a second one.

Keep raw data

Land the source data unchanged before transforming it. If a transformation bug is found next month, you can rebuild from raw files instead of asking the source system for history it may no longer have.

Backfills become easy

Once each window is self-contained and replaceable, fixing a bad month is just running the pipeline for those 30 dates. That's the real payoff: recovering from mistakes stops being an emergency.