1 min read

Stream Backfill vs Batch Backfill: Key Differences

Compare stream backfill vs batch backfill, including state, offsets, late data, idempotent SQL replay, and checks that prevent gaps and duplicates.

Stream Backfill vs Batch Backfill: Key Differences

Backfill is historical data processing. Streaming backfill replays that history through a streaming, incremental pipeline, so it is bounded replay, not simply new data arriving in real time. Batch backfill reprocesses history in large scheduled chunks. The difference is how you replay the past and control correctness, not when events show up.

By jackey.ye, Updated 2026-11-27

Key Takeaways

  • Backfill always means processing historical data; streaming backfill replays that history through the same pipeline that handles live events.

  • Bounded replay is the defining trait of streaming backfill, so check per-partition source offsets and log retention before you start.

  • A batch backfill reprocesses history in large scheduled chunks and reruns failed chunks instead of the whole job.

  • Safe replay depends on event time, watermarks, late-event handling, and idempotent sinks, not on delivery slogans.

  • Validate data before and after backfilling, and treat "deterministic rerun" as different from "correct under updates and deletes."

Definitions

Definitions

Image Source: pexels

The Misconception Worth Fixing

The usual framing, "stream backfill is real time, batch backfill is not," misses the point. Backfill is not about live traffic at all. It means processing data that already exists: reprocessing a past time range to fill gaps, fix logic, or onboard a new dataset. Streaming backfill takes that historical range and replays it through a streaming or incremental pipeline. So the real distinction is bounded replay versus a live stream, not new data arriving now.

A bounded replay reads a finite slice of history between two offsets or timestamps, then stops. A live stream keeps running. Teams conflate the two because both use the same code path. That is exactly why replay needs its own controls: a start offset, an end condition, and a way to reconcile what you rewrote.

What Is Streaming Backfill?

Streaming backfill replays historical records through the same operators and sinks that process live events. You define a bounded range, often [start, end), using source offsets or event timestamps rather than "whatever arrives next." The pipeline is incremental: it processes the range in order and updates state as it goes. Flink documents this model as stateful stream processing, where state and stream positions are snapshotted together so a replay and a live run share the same semantics.

Because the replay runs through production logic, everything that applies to live traffic also applies here: event time, watermarks, late events, and idempotent writes. Those are covered below.

What Is Batch Backfill?

Batch backfill reprocesses history in large chunks on a schedule, usually through a separate path from the streaming system. You point it at a bounded time range, rebuild or repair a table, and rerun only the chunks that fail. It favors control and throughput over latency: you can throttle it, run it off-peak, and inspect each chunk before moving on.

Neither approach is "real time" in the backfill sense. Both are bounded jobs over historical data. The difference is the execution path and the correctness tools each one gives you.

Stream Backfill vs Batch Backfill

Key Differences

Image Source: unsplash

Six dimensions separate the two methods. The table below frames each one around bounded replay versus scheduled reprocessing, so you can see where correctness and cost actually live.

Dimension

Stream Backfill

Batch Backfill

Execution path

Replays a bounded range through the streaming or incremental pipeline

Reprocesses a bounded range through a separate batch path

Bounded replay vs live

Reads a finite [start, end) and stops; the live stream keeps running

Always finite; no live arm at all

Time semantics

Event time plus watermarks; windows can be ordered per key, but not across partitions

Can also use event time, since batch engines support event-time windows too

State handling

Restore from a snapshot or bootstrap from empty state, depending on the job

Usually recomputed from scratch, or seeded from a prior result

Duplicate handling

Needs sink idempotency or upsert to survive replays

Rewrites target partitions; duplicates depend on the write mode

Source offsets and retention

Tied to source offsets and log retention; must rewind safely

Still bound by retention whenever the input is a log or change stream

Time Semantics in Streaming Backfill

Replay correctness starts with event time. Event time is when the event actually happened; processing time is when your pipeline handles it, and the two drift apart during a replay. Apache Flink's timely stream processing model uses event time as the basis for results, and watermarks to signal that a time window is probably complete. When a replayed record carries an event time earlier than the current watermark, it is a late event, and you must decide whether to drop it, route it to a side output, or trigger an allowed-lateness update.

Offsets and time both matter. During replay you rewind the source to a saved position and let the pipeline advance. Event time orders the data logically; offsets control where you physically start reading. Get the mapping wrong and a "replayed" window can silently miss records that sit just before your start offset.

Nothing here should promise universal exactly-once delivery. Exactly-once is a property of a specific source, sink, and configuration, so verify it against your target environment rather than assuming it holds everywhere.

State, Offsets, and Idempotency

A replay is only safe when the pipeline starts from a known point, carries the right state, and writes in a way that survives a rerun. Three controls do that work.

State Restoration and Bootstrap

Before replaying, decide what the operators need. Apache Flink distinguishes checkpoints and savepoints: checkpoints are periodic snapshots for automatic recovery, while savepoints are user-triggered snapshots you use to stop-and-resume, fork, or bootstrap a new job with preserved state. A streaming replay can either restore an existing snapshot or bootstrap from empty state and rebuild it while reading the range. Neither is always right. Restoring stale state can double-count; rebuilding from scratch on a huge range costs time and compute.

Stable operator IDs matter here. Flink maps snapshot state to operators by ID, so renaming a stage can leave state unmapped. Keep IDs fixed across replays.

Source Offsets and Retention

Your source defines the rewind point. In Apache Kafka, a consumer tracks a committed position per partition and can move it with seek(), so you can re-read older records from a saved offset. The KafkaConsumer documentation notes that auto.offset.reset only applies when there is no valid committed offset or the requested offset falls outside the retained log. That detail decides whether a replay works at all: if the start offset has aged out of retention, the source cannot serve it and your backfill silently begins somewhere else.

Retention is not a streaming-only concern. Batch backfill reading a change log, a CDC stream, or a short-lived staging table hits the same wall, so confirm the data still exists before you plan a range. Save the offset of the next record to process, not the last one you handled, and check the earliest available offset before rewinding.

Sink Idempotency and Reconciliation

Replays repeat work, so your sink must tolerate seeing the same record twice. An upsert keyed on a stable event ID makes repeated writes land on the same row instead of creating duplicates. After the replay, reconcile: compare row counts and checksums for the replayed window against the source, and look for gaps at the window edges. Reconciliation is what turns "the job finished" into "the data is right." The Medallion quarantine and replay pattern isolates failed rows so a rerun touches only what broke.

Cost deserves a look too. Replays concentrate compute into short bursts, and that peaks on your bill; the cost analysis of data replay compute peaks breaks down where those spikes come from.

Deterministic Rerun vs Correctness Under Updates

Two questions get confused. A deterministic rerun means the same input produces the same output, so a retry is safe and cheap. Correctness under updates and deletes is harder: if a source row was later corrected or deleted, replaying the original events reproduces the old result, not the current truth. Batch backfill rebuilt from a current snapshot may reflect deletes; streaming replay needs those deletes captured as tombstone records. Know which one your pipeline gives you before you promise a number.

How to Run a Safe Streaming Replay

Work through these steps in order. Each one removes a specific failure mode.

  1. Define the bounded range. Pick a half-open window, [start, end), in event time so no record sits on both edges.

  2. Verify retention. Confirm the source still holds every offset or timestamp in the range before you rewind.

  3. Capture the start offset. Record the next record to process per partition so the replay is reproducible.

  4. Prepare the sink. Enable an idempotent write, such as an upsert keyed on a stable event ID.

  5. Restore or bootstrap state. Load a savepoint, or start clean and rebuild state across the range. Keep operator IDs stable.

  6. Replay and watch watermarks. Let event time drive windows and route late events to a handled path.

  7. Reconcile. Compare counts and checksums for the window and inspect the edges for gaps or duplicates.

A Small Idempotent Replay in PostgreSQL

Sink idempotency is easier to see in code. The example below targets PostgreSQL 15+ and replays a bounded event window into an aggregate sink keyed on account and window. It uses ON CONFLICT ... DO UPDATE so running it twice produces the same rows. This example has not been executed here; validate it in your own target environment, since table settings, indexes, and types differ.

First, the tiny fixture: a source events table and an aggregate sink.

-- Fixture: three events inside the window, one outside it.
  CREATE TABLE raw_events (
    event_id   uuid          NOT NULL,
    account_id text          NOT NULL,
    amount     numeric(12,2) NOT NULL,
    event_time timestamptz   NOT NULL,
    PRIMARY KEY (event_id)
  );
  
  CREATE TABLE account_totals (
    account_id text          NOT NULL,
    window_end timestamptz   NOT NULL,
    total      numeric(14,2) NOT NULL,
    PRIMARY KEY (account_id, window_end)
  );
  
  INSERT INTO raw_events (event_id, account_id, amount, event_time) VALUES
   ('11111111-1111-1111-1111-111111111111','A1', 10.00, '2026-11-01T09:10:00Z'),
   ('22222222-2222-2222-2222-222222222222','A1', 15.00, '2026-11-01T09:40:00Z'),
   ('33333333-3333-3333-3333-333333333333','A2', 20.00, '2026-11-01T09:50:00Z'),
   ('44444444-4444-4444-4444-444444444444','A1',  5.00, '2026-11-01T10:15:00Z'); -- outside window
  

Now the idempotent replay. The window is half-open: [2026-11-01T09:00:00Z, 2026-11-01T10:00:00Z), so the 10:15 event is excluded.

-- Idempotent replay of a bounded, half-open window into an aggregate sink.
  INSERT INTO account_totals (account_id, window_end, total)
  SELECT account_id,
         TIMESTAMPTZ '2026-11-01T10:00:00Z',   -- window_end for [start, end)
         SUM(amount)
  FROM raw_events
  WHERE event_time >= TIMESTAMPTZ '2026-11-01T09:00:00Z'
    AND event_time <  TIMESTAMPTZ '2026-11-01T10:00:00Z'
  GROUP BY account_id
  ON CONFLICT (account_id, window_end)
  DO UPDATE SET total = EXCLUDED.total   -- rerun overwrites, never appends
  RETURNING account_id, total;
  

Expected output: two rows, A1 with 25.00 and A2 with 20.00. The 10:15 event is left out because the window is half-open, and a second run updates those same rows instead of adding new ones. That is what the ON CONFLICT clause gives you, as the PostgreSQL 15 INSERT documentation describes together with RETURNING.

Rerun only the replay INSERT, not the fixture CREATE TABLE and seed INSERT statements. The upsert replaces totals for groups that still exist. If all source rows for a group are deleted or move out of the window, its old sink row remains; rebuild the complete window transactionally or explicitly delete obsolete groups. Coordinate concurrent writers and reconcile before publishing results.

FAQ

Is streaming backfill the same as real-time processing?

No. Streaming backfill replays historical data through a streaming pipeline; it is bounded replay, not live traffic. The pipeline happens to be the same one that handles real-time events, which is why the two get mixed up.

When is a replayed time window complete?

A window is complete when the watermark passes its end. Before that, records with earlier event times can still arrive. Size allowed lateness by how out-of-order your sources are, then treat anything later as a late event you handle explicitly.

Will a replay create duplicate records?

Duplicates depend on both the input and write strategy. A stable event key can deduplicate source records, while an idempotent upsert can prevent repeated sink rows. Neither alone proves aggregates are correct or that concurrent writers are coordinated.

Can I run the same replay twice?

Yes, if the write is idempotent and the input is deterministic. A deterministic rerun means the same range yields the same result, which makes retries safe. Just confirm your sink deduplicates on the event key.

Does replay reproduce deletes and corrections?

Not from raw insert events alone. Replaying original events reproduces the old state. To reflect a later delete or correction, you need tombstone records or a rebuild from the current source snapshot. That is the gap between a deterministic rerun and true correctness under updates.

See Also

Understanding Data Pipelines: A Comprehensive Introduction

The Role of Apache Kafka in Efficient Data Streaming

Four Key Algorithms for Scalable Daily Replenishment

Essential Insights on ETL Tools for Beginners

Navigating the Complexities of Dual Pipelines in LambdaA watermark passing the window end can trigger evaluation; it does not prove all source records arrived. Completion also depends on bounded source end offsets, retention, late-event handling and reconciliation.

Related Articles