Evaluating synchronization issues
I'm considering the implications of unioning with live data—having a low minimum watermark could stall everything. If not unioned, a sink expecting continuous data might face issues like duplicates or out-of-order events. I see a couple of solutions: one is to separate the sink and reconcile the data, and the other is to gate the watermark. However, gating can disrupt event time correctness, so I'd only do that if treating backfill results as corrections rather than triggers. I should also mention the difference between "retractions” and “overwrites," specifically regarding upsert logs versus file rewriting.
Backfills are “time travel” in a system whose correctness is defined by watermarks. If you don’t design for that explicitly, backfills either (a) get dropped as late data, (b) corrupt previously-final results, or (c) stall the whole pipeline by dragging watermarks backwards/low.
Below is a practical way to reason about watermark shifts, retractions, and correctness, plus safe patterns that work in most streaming engines (Flink/Spark/Kafka Streams/etc.).
1) Why backfills are unsafe by default (watermarks + state)
Watermark invariants (event-time systems)
- Watermarks are (typically) monotonic and represent “we don’t expect more events with event_time ≤ watermark”.
- Many operators treat “watermark passed window end” as finalization:
- window emits “final” result
- state may be cleaned up after
allowed_lateness / retention
- late events may be dropped or routed to a late side output
What a backfill does
A backfill injects events with event_time in the past relative to:
- the live job’s current watermark, and/or
- the already-materialized outputs.
So unless your system is configured to keep state and accept lateness long enough, the backfill becomes:
- late → dropped, or
- late → updates needed, but state is gone, so you can’t fix aggregates correctly.
Key implication:
If your “live” job has already advanced its watermark beyond the backfill interval and cleaned state, you generally cannot safely “patch” correctness in-place by just replaying older input into the same running topology.
2) Watermark shifts: the two common failure modes
A) Backfill stream stalls the global watermark (when unioning)
In many engines, when you merge/union streams, downstream watermark is effectively the min across inputs. If one input is replaying old time, downstream event-time progress can freeze for hours/days.
Symptoms:
- windows stop closing
- timers don’t fire
- state grows
- “latency” metrics explode (even though CPU is fine)
Rule: Don’t mix a slow historical replay watermark with a live watermark unless you explicitly isolate/alignment-control it.
B) Backfill events are “too late” for the live watermark
If the live watermark is at W_live, then events with event_time < W_live - allowed_lateness are late beyond tolerance:
- they’re dropped, or
- they can’t update because state is already evicted.
3) Retractions: what they are and when you need them
Retractions = changelog semantics
To correct already-emitted results, your output must support updates, not just appends.
Common forms:
- Upsert keyed by
(entity_id, window_start/end, …) with a deterministic primary key
- Changelog stream with
INSERT/UPDATE_BEFORE/UPDATE_AFTER/DELETE (a.k.a. “retractions”)
- Partition overwrite for immutable file layouts (overwrite day/hour partitions)
You need retractions/updates if:
- you already published aggregates as “final” (or consumers treat them as final), and
- backfill changes those aggregates.
If your sink is append-only and your consumers can’t reconcile updates, you must do shadow + swap or overwrite partitions, not “emit corrections” into the same append log.
4) Safe backfill patterns (in practice)
Pattern 1 — Recompute into a new output, then swap (safest)
How it works
- Run a bounded/batch job over the historical interval (or full history)
- Write results to a new table/topic/path
- Validate (counts/checksums/drift)
- Atomically “swap” consumers to the new output (or update a view pointer)
Pros
- No watermark interference with live
- No retraction burden on downstream
- Strongest correctness story
Cons
- Requires dual outputs + cutover plan
- Might be expensive (but predictable)
Use when: you can’t guarantee downstream can process retractions.
Pattern 2 — Corrections as upserts/changelog (works if downstream supports it)
How it works
- Keep live pipeline running
- Run backfill pipeline separately
- Produce keyed corrections (upserts or changelog) into the same logical sink, or into a “corrections” stream/table that is merged downstream.
Critical requirements
- Deterministic key for the “row” you’re correcting (e.g.
(user_id, window_end)).
- Sink supports idempotent upsert / merge (DB upsert, Iceberg/Delta/Hudi MERGE, Kafka compacted topic, etc.).
- Consumers are defined on latest-by-key semantics (or they apply the changelog).
Pros
- No need to rewrite huge partitions if corrections are sparse
- Live keeps flowing
Cons
- You’ve changed the contract: results are no longer “append-only facts”, they’re mutable.
- Watermark-finalization semantics move from “final at watermark” to “eventually correct”.
Use when: your organization accepts eventual correction and has upsert-capable sinks.
Pattern 3 — Full replay with state reset (only if you can afford it)
How it works
- Stop the job (or deploy a new one)
- Reset offsets / replay input from earlier point
- Recompute outputs (often to a new sink), then cut over
Pros
- Simple conceptual model: one pipeline recomputes everything
Cons
- Operationally heavy; long catch-up times
- If you write to the same sink, you must guarantee idempotency or isolation
Use when: you need to correct logic globally and can tolerate rebuild.
5) Watermark handling guidelines for backfills
Don’t “union live + backfill” unless you mean to
If you combine them in one topology, you must answer:
- What is the downstream watermark definition?
- Do you accept stalling watermarks while historical catch-up runs?
If you must combine:
- use watermark alignment/idleness features (engine-specific) so an “idle” backfill input doesn’t hold back progress
- or gate the backfill so it runs fast and completes, then disappears
Avoid “watermark hacking” for correctness
Artificially forcing the backfill watermark forward (to avoid stalling) can cause:
- windows to close before the backfill data is seen → wrong results
So only do that if the backfill output is not using event-time windowing semantics (i.e., you’re producing corrections by key, not relying on watermark-driven finalization).
6) Correctness checklist (what to decide up front)
-
Output contract
- Append-only facts?
- Upserted dimension/aggregate?
- Changelog with retractions?
-
Finality
- Are results final at watermark time, or only “provisional until X days”?
- If provisional, define the correction horizon explicitly.
-
State retention vs. lateness
- If you want “in-place late updates”, state must survive until the backfill horizon:
state_retention >= max_backfill_lookback
allowed_lateness >= max_backfill_lookback
- This is often impractical beyond hours/days.
-
Idempotency
- Replays happen. Ensure sinks can dedupe by key + version, or transactional writes.
-
Consumer behavior
- Can consumers handle updates/retractions?
- If not, you must backfill by overwrite/swap.
7) A simple rule of thumb
- If you need strong correctness and your sinks/consumers are append-only → recompute elsewhere and swap/overwrite.
- If you need continuous operation and can support mutable outputs → emit backfill as upserts/changelog.
- If you try to “just replay old events into the live job” without large lateness/state retention → you’ll get drops, stalls, or silent wrong aggregates.
If you share:
- engine (Flink/Spark/etc.),
- sink type (Kafka topic, lakehouse table, OLAP DB),
- whether the output is windowed aggregates or per-event enrichment,
I can recommend a concrete backfill plan (including how to set watermark/allowed lateness/state TTL and what correction format to emit).