Articles · Data engineering · · 9 min read
Idempotent Pipelines and Backfills You Can Rerun
Backfills fail quietly when a pipeline isn't idempotent. Window parameters, write strategies, isolation, and the downstream refresh everyone forgets.
By Matthieu de La Mettrie · Founder, Skopura
A platform owner can usually tell you the last time a backfill went wrong, because the symptom is never a red task. The symptom is a metric that moved for no reason, a duplicate that survives a dedupe test because the dedupe test was written against the natural key and the duplicate differs by a load timestamp, or a report that disagrees with the warehouse because nobody refreshed the matching partitions downstream. Reruns are the single most common operational action on a data platform and the one least likely to have been designed for.
What does idempotent actually mean for a pipeline?
The useful definition is narrow: rerunning a task for the same logical window leaves the target in the same state as a single successful run for that window. Not the same bytes, not the same file layout, not the same run metadata — the same queryable state.
That distinction matters because people conflate idempotency with determinism and then conclude it’s impossible. Source systems mutate. A row that arrived as pending may be settled by the time you replay the window. If you demand that a replay reproduce the original output exactly, you need an immutable source snapshot and you have signed up for a far larger problem. What you actually want is convergence: replaying a window produces the state that a first run would produce given what the source says now, and replaying it twice in a row changes nothing the second time.
Once you accept convergence as the goal, the design constraints fall out. Every task takes the window as a parameter. Nothing in the transformation reads the clock. Writes replace rather than accumulate. Side effects are deduplicated on a key that includes the window.
Why does run time keep leaking into the logic?
Because it is convenient, and because it hides in places that don’t look like business logic.
The obvious case is a filter on current_date or a watermark read from a mutable control table. Replay that task three days late and it quietly processes a different window than the one the orchestrator asked for. The control table is the worse of the two, because it makes the pipeline’s behaviour depend on execution history rather than on inputs — the task is no longer a function of its parameters. A high-water mark is fine as an observation you record, and dangerous as a control you read back.
The less obvious cases: sequence-generated surrogate keys that renumber on every load, so a replay breaks every foreign key written by an earlier run; inserted_at columns used in downstream window functions, where the ordering flips on replay; an SCD2 model that compares each batch to the current state of the dimension, so replaying an earlier window opens a version that was already closed. None of those look like clock dependencies in review. All of them are.
Hash your surrogate keys from the business key and effective date. Keep audit timestamps in audit columns and keep them out of joins and window functions.
Which write strategy makes a rerun safe?
Append never does. Everything else is a trade.
| Merge on business key | Overwrite the window | |
|---|---|---|
| Rerun behaviour | Converges if the key is stable and complete | Converges by construction — the window is rebuilt |
| Hard deletes in source | Invisible unless you emit tombstones | Handled, provided the deletion is within the window |
| Late-arriving records | Absorbed naturally | Absorbed only if you replay the window they belong to |
| Dependency on key quality | Total — a duplicate or null key corrupts silently | None — the partition predicate is the contract |
| Work done on a rerun | Proportional to changed rows | Proportional to window size |
| Failure mode when wrong | Duplicates or stale rows that pass row counts | A window written empty because the predicate missed |
In dbt this is the merge versus insert_overwrite decision, and the thing worth pinning down is that it is not primarily a performance decision. It’s a decision about which failure you’d rather debug. Partition overwrite fails loudly and locally: a bad predicate empties a window and anyone looking at the data sees a hole. Merge fails quietly: a duplicate key or a key that changed upstream leaves two rows where there should be one, and the metric drifts without a single test going red.
{{ config(
materialized = 'incremental',
incremental_strategy = 'insert_overwrite',
partition_by = { 'field': 'event_date', 'data_type': 'date' }
) }}
with bounds as (
select
cast('{{ var("window_start") }}' as date) as window_start,
cast('{{ var("window_end") }}' as date) as window_end
),
source as (
select *
from {{ ref('stg_events') }}, bounds
where event_date >= bounds.window_start
and event_date < bounds.window_end
)
select
{{ dbt_utils.generate_surrogate_key(['event_id']) }} as event_sk,
event_id,
event_date,
customer_id,
amount
from sourceThe half-open interval is not pedantry. Inclusive upper bounds are how adjacent backfill windows end up writing the same boundary row twice under a merge, and how a partition overwrite ends up clobbering the first row of the next window.
Can the windows run in parallel?
Only if each window’s output depends solely on that window’s input. That property is worth testing explicitly rather than assuming, because the models that violate it are the ones you most want to backfill: running balances, SCD2 dimensions, sessionisation that spans a boundary, anything cumulative.
Order-dependent and clock-dependent. Don't backfill — rebuild the model end to end into a new table and swap.
For the order-dependent models, stop trying to make the incremental path replayable and make the full rebuild cheap instead. A dimension you can rebuild from an immutable event log in a single statement is less operational risk than one with a clever replay procedure that is exercised twice a year under pressure.
Where should a backfill actually run?
Not in the table the business is reading, if you can avoid it.
The pattern that holds up: build into an isolated target — a separate schema, a shadow table, a cloned catalog, a dedicated workspace — validate against the live table, then swap or merge the validated output in one atomic operation. Zero-copy cloning makes this cheap enough on a lakehouse that there’s little excuse for running a wide backfill in place. Fabric and Databricks both give you workspace- or catalog-level separation, and dbt gives you target schemas; the mechanism matters less than the discipline of having a place to be wrong.
Validation is where most backfill plans are thin. Before the swap, compare the shadow output against the live table for windows that weren’t backfilled. If those rows differ, your backfill logic differs from your production logic and you are about to overwrite good data with a refactor nobody reviewed.
Capacity is the other constraint. A backfill is a burst of work on the same capacity that serves scheduled loads and interactive queries. Chunk it, cap concurrency, and give it a lower priority than the daily path. A backfill that takes a weekend and hurts nobody beats one that finishes by lunch and pages the on-call.
What breaks downstream when the warehouse is rewritten?
The thing that gets forgotten, consistently, is that the warehouse is not the last copy of the data.
Incremental refresh processes only changed partitions rather than a full dataset — which is exactly why a warehouse backfill can leave a Power BI model untouched. The semantic model has no idea that historic partitions were rewritten; it refreshes the recent window on schedule and keeps serving the old numbers for everything behind it. The warehouse and the report now disagree, and the disagreement is invisible until someone cross-checks a figure from a year ago.
Treat the downstream refresh as part of the backfill, not as a follow-up. If you backfilled a set of windows, you need a mechanism that re-drives the corresponding partitions in every consumer that caches: semantic models, materialised aggregates, extracts, anything exported to another system. The cleanest version of this is a backfill manifest — the list of windows you touched — that the orchestrator hands to each downstream refresh step.
What does getting this wrong actually cost?
Rarely a single outage. The cost compounds in two directions.
The first is silent corruption: duplicates and double-counted partitions that survive because row-count tests pass and uniqueness tests were written on a composite key that includes the load timestamp. These surface weeks later as an unexplained metric step, and the investigation consumes more engineering time than the original load ever did.
The second is worse and harder to see: the team stops trusting reruns. When nobody is confident that replaying a task is safe, failures get fixed with ad-hoc SQL in a notebook. That SQL isn’t in version control, isn’t in the lineage, and isn’t reproducible. The platform accumulates manual corrections that no rebuild will ever reproduce, and the first genuine full rebuild — a migration, a vendor change, a schema redesign — produces numbers that don’t match production, with no way to explain the gap.
Idempotency is what makes a rerun boring. Boring reruns are what let you fix things quickly, migrate without a reconciliation project, and recover from an upstream correction without a meeting.
What would you put in place first?
Start with the parameter. If tasks don’t already take an explicit window and pass it through to the transformation, nothing else is enforceable — every other control is defeated by a model that reads the clock. Then audit the write strategies and find the appends. Then pick your most order-dependent model and decide, deliberately, whether you are making it replayable or making it rebuildable; those are both valid answers and the failure is having neither.
After that, the test is cheap and worth automating: in a non-production target, run a window, snapshot the output, run the same window again, and diff. Any model where the second run changes the result is a model that will quietly corrupt the warehouse the first time someone retries a failed task at an awkward hour.
data-engineering · orchestration · dbt · backfills
Share on LinkedIn ↗Work with Skopura
Facing this bottleneck in your own estate?
Skopura builds production-grade lakehouse pipelines, evaluation harnesses, and provides fractional data leadership. Thirty-minute call, no deck.