Evolving from Pure CDC to Full Data Synchronization with DBLog-Based Incremental Snapshots

DBLog was introduced at Netflix in 2019 to capture both the live transaction log and the full state of a source database in a single, ordered stream without stalling writes or the log event propagation. That design became the foundation for incremental snapshots in Debezium and Apache Flink CDC and in a previous work we showed that they are all part of the same family.

Beyond capturing full tables, the original DBLog approach also allows repairing specific entries in place. However, because it only emits rows that exist at the source, this is limited to fixing missing rows or updating their values, while deleting orphan rows (rows that sit in a downstream sink even though they do not exist at the source) is not supported.

A source database with an orders table and its transaction log, a CDC connector that streams the log and re-reads the table in chunks, and a sink. A repair pass overwrites the outdated value of order 2 and restores the missing order 3, but order 4, which no longer exists at the source, stays in the sink.
Figure 1: A minimal CDC pipeline. The connector streams the source's transaction log and re-reads the orders table in chunks. A repair pass overwrites the outdated value of order 2 and restores the missing order 3, but order 4, which no longer exists at the source, stays in the sink.

In our new paper, Extending DBLog-Based Incremental Snapshots to Handle Orphan Rows in CDC Pipelines, we solve this problem by extending the DBLog design so that a pipeline can also detect and remove orphan rows. With this addition, a CDC pipeline that is using DBLog-style incremental snapshots becomes a complete data synchronization engine whether a sink catches up on live changes or missing rows (empty sink or lost inserts), holds wrong column values (corrupted data or lost updates), or contains rows it should not have (orphan rows).

This post explains the core idea for practitioners, which applies to Debezium, to Apache Flink CDC with a small adaptation and to any connector built on DBLog-based incremental snapshots: why CDC naturally evolves towards full data synchronization, why orphan rows are the missing piece when keeping populated sinks in sync and how to remove them safely through the stream while live changes keep flowing.

Three Steps from Pure CDC to Full Data Synchronization

If you look at how teams use CDC in production, the role of the pipeline is evolving across three steps. Solving each step addressed an operational limitation of the previous one and opened the door to the next.

Step 1: Pure CDC. Early CDC connectors read committed INSERT, UPDATE and DELETE records from the database transaction log and put them on a stream. For event-driven microservices and audit logs, streaming those change events was enough. However, most deployments use CDC to maintain a derived copy of a source database in one or more sinks, such as a search index, a cache, a read replica or a data warehouse. Transaction logs are retained only for a limited time or size, so log tailing alone cannot populate a new sink.

Step 2: Source state capture. To also capture existing rows, connectors such as Debezium first used one-time initial snapshots at startup, which pause log propagation until the full scan finishes and reaches the sink and may briefly lock tables. Adopting the DBLog design as incremental snapshots in Debezium and Flink CDC broke scans into small chunks interleaved with the live log, enabling a continuous flow of both snapshots and live changes as well as on-demand repairs that refresh specific keys or tables in place.

Step 3: Full data synchronization. That ability to refresh keys in place against an already populated sink leads to the next step: full data synchronization, whose goal is to continuously converge a sink towards the source no matter how the sink lags or has drifted. This covers a lagging sink catching up on live INSERT, UPDATE and DELETE events as they occur at the source, closing gaps of missing rows via source SELECT capture (such as pre-existing rows when bootstrapping an empty sink) and repairing drift when a sink has dropped events along the way, applied wrong column values, or accumulated extra entries from another writer.

This evolution happens across three dimensions:

  • What the pipeline reconciles (scope): from streaming live change events, to capturing present table state, to full synchronization that covers missing rows, wrong column values and orphan rows.
  • When state capture runs (lifecycle): from a one-time full bootstrap of an empty sink at startup, to on-demand and periodic repairs that refresh specific keys or tables in place.
  • How it runs alongside live traffic (continuity): from stopping source writes or pausing log propagation during a snapshot scan, to a continuous flow of both live changes and state capture on the same stream.
Three steps. Step 1 emits change events from the log, so a sink follows live changes. Step 2 adds chunk rows interleaved with the log, so a sink can be bootstrapped and repaired in place for missing rows and wrong values. Step 3 adds the keys a chunk read found absent, so orphan rows are removed too. Steps 1 and 2 are where CDC is today. Step 3 is the next step.
Figure 2: Each step adds one kind of output. Change capture streams the log. Source state capture adds chunk rows, which bootstrap a sink and repair it in place. Orphans are the one case it misses, since a chunk read emits only the rows it finds. Full synchronization adds the keys a chunk read found absent, so orphan rows are removed too.

That shift from populating an empty sink to repairing a populated sink is where orphan rows appear.

When you stream a snapshot into an empty sink, emitting only the rows currently present at the source is enough because any key the snapshot never mentions is absent by construction. When you re-run an incremental snapshot against an already populated sink, emitting present rows fills in missing rows and overwrites wrong column values, because each chunk emits the latest state of every row that exists. However, if the sink holds a row whose key does not exist at the source, the chunk SELECT does not return that key. Nothing is emitted for it and the extra row stays in the sink forever.

How Orphan Rows Arise and What a Chunk Read Already Knows

Orphan rows show up in populated sinks for a handful of recurring operational reasons:

  • Source log gaps and failovers. A connector falls behind a MySQL binlog purge, a PostgreSQL WAL segment cleanup or an unpromoted replica failover. Any DELETE that committed during that gap never reaches the stream.
  • Source point-in-time recovery. When a source database is restored to an earlier backup after an incident, rows inserted after the backup timestamp cease to exist at the source without producing DELETE records in the log.
  • Downstream pipeline filtering or delivery bugs. A bug in a stream processor, a schema filter change or a dead-lettered batch drops DELETE events before they reach the sink.
  • Side writes to the sink. A backfill script, manual hotfix or dual-writing service writes a row directly into the sink that was never committed at the source.

Take an orders table with integer primary keys. Suppose keys 1 through 10 were replicated earlier and orders 4 and 7 were later deleted at the source during a log gap so the sink still holds all ten rows 1..10.

To repair the sink, we run an incremental snapshot pass whose first chunk covers keys up to 10, meaning the half-open key interval (-∞, 10]:

SELECT pk, customer_id, total, status
FROM orders
WHERE pk <= 10
ORDER BY pk

The watermark table lives in the source database, so writes to it appear in the same transaction log as changes to orders. A DBLog-style incremental snapshot executes this chunk read alongside the live log as follows:

  1. The connector briefly pauses log processing and writes a low watermark LOW into the source watermark table.
  2. It runs the chunk SELECT for pk <= 10, holding the returned rows in memory. Suppose the query returns eight rows: 1, 2, 3, 5, 6, 8, 9 and 10.
  3. It writes a high watermark HIGH into the watermark table, resumes log processing and reads the log up to HIGH. Suppose order 9 is updated in the log between LOW and HIGH. The connector emits that live UPDATE 9 event and drops key 9 from its buffered chunk rows so the older chunk value cannot overwrite the newer log event.
  4. When HIGH arrives in the log, the connector closes the chunk and emits the surviving chunk rows: 1, 2, 3, 5, 6, 8 and 10.
Between the low and high watermarks the connector selects keys up to 10 while order 9 is updated in the log. The read returns 1, 2, 3, 5, 6, 8, 9 and 10 and proves 4 and 7 are absent, yet existing incremental snapshots emit only the present rows.
Figure 3: A watermark-bracketed chunk read over pk <= 10 returns keys 1, 2, 3, 5, 6, 8, 9 and 10 while key 9 is updated inside the window. The read proves that 4 and 7 do not exist in (-∞, 10], yet existing incremental snapshots emit only the present rows and leave 4 and 7 in the sink. Capturing that fact inside the watermark window lets the pipeline remove orphans with the same safety guarantee.

At HIGH, the connector already knows more than which rows exist. Because the query scanned the entire range pk <= 10 after LOW and the connector observed every log event between LOW and HIGH, the set of keys that exist at the source in (-∞, 10] at the high watermark is covered by the union of the keys selected by the query (1, 2, 3, 5, 6, 8, 9, 10) and any keys touched in the window (9). Every other key in (-∞, 10], including 4 and 7, is absent at the high watermark, provided the chunk query sees every transaction logged before LOW. The connector enforces this on PostgreSQL, where a transaction can be logged before a query can see it.

Existing incremental snapshot implementations discard that negative information because they only emit events for the rows the query returned.

Why Out-of-Band Deletes Race with Live Data

Before modifying the connector, it is tempting to reach for an external script that queries the source keys, compares them against the sink keys and runs DELETE FROM orders WHERE pk IN (4, 7) directly on the sink.

In a quiescent database, that works. On a live table, an out-of-band delete has no position in the replication stream, which opens a classic time-of-check to time-of-use race whenever a key can be re-created or re-inserted (for example, an account re-registration, a composite mapping key, a natural key or an undo operation that restores a deleted order).

Top: When absence is emitted at the high watermark, a later re-insert of order 7 follows the delete in stream order and survives. Bottom: When an external diff job issues an unpositioned delete directly against the sink, it can arrive after the re-insert and delete a live row.
Figure 4: Top: When absence is emitted at HIGH, a later INSERT 7 follows the delete in stream order and the live row survives. Bottom: An external diff job that deletes directly from the sink has no position in the stream, so its delete can land after INSERT 7 and remove a live row.

As Figure 4 illustrates, suppose order 7 is re-inserted at the source shortly after the read:

  • In-band at the high watermark (top): The absence of 7 is emitted at HIGH, before the log reaches the later INSERT 7. The sink deletes the stale orphan 7 at HIGH and then applies INSERT 7 from the stream, ending with the new live row.
  • Out-of-band diff job (bottom): The diff job reads the source while 7 is absent, then reads the sink and prepares to delete 7. In the meantime, INSERT 7 commits at the source and flows through the CDC stream to the sink. When the diff job’s direct DELETE 7 finally executes against the sink, it deletes the newly created live row and the stream has no later event to bring it back.

The simplest way to delete orphans safely without stopping writes is to anchor the absence of a key at the high watermark of the read that observed it, just like present chunk rows are.

Extending Incremental Snapshots: Three Building Blocks

In the paper, we extend the DBLog incremental snapshot design with three building blocks: a chunk info record, its per-key rendering as absence events and a repair request that an external drift process can call.

Building Block 1: Chunk Info Records

The most direct way to express what a chunk read learned is to emit a chunk info record at the high watermark, immediately ahead of the chunk’s surviving row events.

Because consecutive chunks partition the table’s key space without gaps, the first chunk covers (-∞, u_1], each middle chunk covers (l_i, u_i] where l_i = u_{i-1} and a tail read WHERE pk > u_n covers (u_n, +∞) once it returns fewer rows than the chunk limit (or under heavy inserts, a pass can cap how many tail chunks it runs and stop at the last upper bound it reached). For our first chunk over pk <= 10, the chunk info record looks like this:

{
  "table": "inventory.orders",
  "read_id": "snap-01-chunk-01",
  "range": {"lower": {"open": true},
            "upper": {"key": 10, "inclusive": true}},
  "selected": [1, 2, 3, 5, 6, 8, 9, 10],
  "changed": [9]
}

Here selected lists the keys returned by the chunk SELECT, changed lists the keys in range that had at least one log event between LOW and HIGH and read_id identifies the read. Their union selected ∪ changed is the exact set of keys in (-∞, 10] that are protected at the high watermark:

  • Any key in (-∞, 10] outside selected ∪ changed was neither returned by the query nor touched in the window, so it does not exist at the source at HIGH.
  • Any key in changed (such as 9) already had its live change emitted during the window and must not be deleted.
  • Any key in selected \ changed (1, 2, 3, 5, 6, 8, 10) is emitted as a surviving chunk row right after the chunk info record.

A sink consumer that applies chunk info records (such as a relational replica or a custom sink service) processes the record in stream order, after every event ahead of it. It deletes every key it holds in range that is neither selected nor changed and then upserts the surviving chunk rows, in one transaction or separately. In our example, that removes orphans 4 and 7, as well as any side-written key below 10, without needing a list of suspect keys.

The same chunk read of keys up to 10, with order 9 updated inside the window. A: at HIGH the connector emits one chunk info record with the range, the selected keys and the changed keys, then the surviving rows. Every key in the range that is neither selected nor changed is stated absent, which covers 4 and 7. B: the connector checks a list of candidate keys 2, 4, 7, 9 and 12. Key 2 was selected, 9 changed and 12 belongs to a later chunk, so it emits absence events for 4 and 7 only, alongside the surviving rows.
Figure 5: The same chunk read, two ways to state absence at HIGH. A: one chunk info record with the range, the selected keys and the changed keys, emitted ahead of the surviving rows. Every key in the range that is on neither list is absent, which covers 4 and 7. B: per-key absence events for the candidate keys found absent, here 4 and 7, which fit key-partitioned topics such as Kafka.

Building Block 2: Per-Key Absence Events

Many pipelines fan out through key-partitioned logs like Apache Kafka or feed off-the-shelf sink connectors (JDBC, Elasticsearch, OpenSearch or Iceberg) that only act on individual keys and do not execute range deletes. On a compacted Kafka topic, the latest record for a key is removed only when a tombstone (key = k, value = null) is produced for that exact key k.

To support these pipelines without changing sink connectors beyond enabling delete-on-tombstone, the connector can resolve the chunk’s absence statement into per-key absence events before putting records on the stream. Given a set of candidate keys C (which the connector can obtain by scanning its own compacted output topic at the start of a pass, or receive from an external caller), the connector filters C to the current chunk’s range and removes selected ∪ changed:

AbsentInChunk = (C ∩ range) \ (selected ∪ changed)

Suppose the candidate set is C = {2, 4, 7, 9, 12}. For our chunk (-∞, 10], the keys inside the range are {2, 4, 7, 9} (while 12 waits for a later chunk). Removing selected ∪ changed = {1, 2, 3, 5, 6, 8, 9, 10} leaves {4, 7}. At HIGH, alongside the surviving chunk rows, the connector emits an absence event for keys 4 and 7, with the operation type absent. On Kafka, it is a standard tombstone by default, with this metadata in the message headers:

{
  "op": "absent",
  "key": { "pk": 4 },
  "source": { "table": "inventory.orders", "read_id": "snap-01-chunk-01" }
}

Sink connectors that delete on tombstones apply these as ordinary deletes for keys 4 and 7, once that option is enabled (such as delete.enabled in the JDBC sinks). For consumers of a CDC envelope that do not know the new type, the connector can map it to delete. Kafka log compaction then also removes keys 4 and 7 from the topic itself.

Building Block 3: The verify-keys-absent Request and External Drift Detection

What if you already have an external drift detector (such as a warehouse reconciliation query or an index validator) that compares the sink against the source, or what if a backfill script or side writer writes orphan key 12 directly into the sink without going through Kafka?

Suppose the detector flags keys 4, 7, 9 and 12 at the sink (where 4, 7 and 12 are genuine orphans, while 9 is a live row that looked suspicious only because the detector compared against a slightly stale view of the source). Instead of letting the external detector delete rows from the sink out of band, we add a verify-keys-absent repair request to the connector’s signaling table:

{
  "id": "drift-check-01",
  "type": "verify-keys-absent",
  "data": {
    "data-collections": ["inventory.orders"],
    "keys": [4, 7, 9, 12]
  }
}

When the connector receives this signal, it runs a lightweight watermark-bracketed cycle specifically for those suspect keys:

  1. It writes LOW and runs a key-list query SELECT pk FROM orders WHERE pk IN (4, 7, 9, 12). It only needs to fetch the primary key column, not the full row payload.
  2. It writes HIGH and tracks any log events for {4, 7, 9, 12} between LOW and HIGH.
  3. At HIGH, for every requested key that was neither returned by the SELECT nor touched in the window, it emits a positioned absence event (a tombstone by default on Kafka) into the stream.
An external drift process inspects the sink and suspects keys 4, 7, 9 and 12. It sends them to the connector with verify-keys-absent. The connector reads those keys at the source between its own low and high watermarks, finds 9 present and 4, 7 and 12 absent, and emits absence events for 4, 7 and 12 at its high watermark. The sink applies them as deletes in stream order, and the live row 9 stays. The drift process never deletes from the sink.
Figure 6: The drift process suspects keys 4, 7, 9 and 12 and sends them with verify-keys-absent. The connector reads them at the source between its own watermarks, finds 9 present and emits absence events only for 4, 7 and 12. The drift process never deletes from the sink.

As Figure 6 shows, a suspect that is still live at the source is safe because the key-list query returns 9 (or the log window shows a change to it), so the connector emits nothing for it and only the confirmed orphans 4, 7 and 12 receive absence events.

Three Operating Modes and Tradeoffs

Because chunk-driven absence and verify-keys-absent share the same watermark mechanism and output events, you can run them in three operating modes depending on your infrastructure:

  1. Mode 1: Fully integrated chunk pass. Every chunk read emits either a chunk info record or per-key absence events (using candidate keys scanned from the connector’s compacted topic). A single pass over the table repairs missing rows, wrong column values and removes orphans. This fits both on-demand recovery after an incident and scheduled periodic sweeps.
  2. Mode 2: External drift process with verify-keys-absent. Chunk reads remain unchanged and only emit present rows. An external drift detector periodically inspects the sink, identifies suspect keys and submits them to the connector via verify-keys-absent. This avoids scanning full table chunks when you only want to clean up suspected orphans and it also catches orphans injected into the sink by side writes outside the pipeline.
  3. Mode 3: Combined mode (recommended for production). You run chunk passes as in Mode 1, while an external drift process submits any residual suspect keys via verify-keys-absent. In the paper, we also describe an end-of-pass bounds hand-off, where the connector publishes the key bounds a pass covered, so an external handler can look for sink keys outside them and submit any it finds via verify-keys-absent.

Figure 7 brings all of this together. It is the high-level architecture of Mode 3 and shows every component of our extension: the chunk passes that state absence, the verify-keys-absent request and the external drift process.

The source database sends CDC events to the connector, and the connector reads table chunks from the source with SELECTs. The connector writes one stream to the sink: a change event for order 9 from the log, rows and an absence event for order 4 from a chunk pass, and an absence event for order 12 from a verify-keys-absent request. The drift process reads the sink keys and sends suspect keys to the connector with verify-keys-absent.
Figure 7: High-level architecture of Mode 3. The connector receives CDC events from the source and reads table chunks with SELECTs. One stream carries change events, chunk rows with their absence statements and absence events for keys confirmed on request. Here order 9 changes in the log, a chunk pass finds 4 absent and a request confirms 12 absent. A chunk pass emits absence events one per key, as shown, or states them in one chunk info record for its range. A request always emits absence events per key. The drift process reads the sink's keys and sends suspects with verify-keys-absent. Solid lines carry events, dashed lines are requests and dotted lines are reads.

Closing

When we look back at the three steps of CDC, the progression is natural. Tailing the transaction log gave us live changes. Adding watermark-aligned chunk reads gave us source state capture so we could bootstrap and refresh derived stores online. Extending those same watermark windows to also emit what the source does not contain turns a CDC pipeline with DBLog-based incremental snapshots into a complete data synchronization engine, whether a sink catches up on live changes or missing rows, holds wrong column values, or contains orphan rows. Our focus in this work is on row-state synchronization and drift, while schema evolution remains out of scope.

The full paper is written with practitioners in mind and goes into further practical detail on applying these mechanisms in Debezium and Apache Flink CDC, handling database-specific edge cases and discussing operational considerations.