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.
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.
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
DELETEthat 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
DELETErecords 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
DELETEevents 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:
- The connector briefly pauses log processing and writes a low watermark
LOWinto the source watermark table. - It runs the chunk
SELECTforpk <= 10, holding the returned rows in memory. Suppose the query returns eight rows:1, 2, 3, 5, 6, 8, 9and10. - It writes a high watermark
HIGHinto the watermark table, resumes log processing and reads the log up toHIGH. Suppose order9is updated in the log betweenLOWandHIGH. The connector emits that liveUPDATE 9event and drops key9from its buffered chunk rows so the older chunk value cannot overwrite the newer log event. - When
HIGHarrives in the log, the connector closes the chunk and emits the surviving chunk rows:1, 2, 3, 5, 6, 8and10.
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).
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
7is emitted atHIGH, before the log reaches the laterINSERT 7. The sink deletes the stale orphan7atHIGHand then appliesINSERT 7from the stream, ending with the new live row. - Out-of-band diff job (bottom): The diff job reads the source while
7is absent, then reads the sink and prepares to delete7. In the meantime,INSERT 7commits at the source and flows through the CDC stream to the sink. When the diff job’s directDELETE 7finally 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]outsideselected ∪ changedwas neither returned by the query nor touched in the window, so it does not exist at the source atHIGH. - Any key in
changed(such as9) 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.
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:
- It writes
LOWand runs a key-list querySELECT pk FROM orders WHERE pk IN (4, 7, 9, 12). It only needs to fetch the primary key column, not the full row payload. - It writes
HIGHand tracks any log events for{4, 7, 9, 12}betweenLOWandHIGH. - At
HIGH, for every requested key that was neither returned by theSELECTnor touched in the window, it emits a positioned absence event (a tombstone by default on Kafka) into the stream.
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:
- 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.
- 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 viaverify-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. - 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 viaverify-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.
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.