dblog-impl · Reference Implementation

DBLog: A Reference Implementation: Executable CDC and full-state snapshots in Java for MySQL and PostgreSQL

A Java 21 reference implementation of DBLog, by its creator Andreas Andreakis. DBLog is a Change-Data-Capture algorithm that copies the full state of a source database alongside live changes, without blocking writes or stalling change event propagation. Built from the published Netflix Technology Blog post (2019) and DBLog paper (2020).

Run lock-free incremental snapshots reconciled against live binlog and pgoutput streams locally, with a paper-to-code audit map and the Hydroscope TUI visualizer.

Java 21 · Spring Boot MySQL 8.0 / 8.4 / 9.6 PostgreSQL 14-18 MIT License
Scripted showcase replay of transaction-log changes and bounded primary-key chunk reads reconciled into one ordered output stream, observed in the bundled Hydroscope TUI.

What this reference implementation includes

Everything needed to study, audit, and test the published watermark algorithm (Algorithm 1 in the paper) locally on real database engines, with no write-blocking table locks and explicit fail-closed guards.

  • Core engine

    Source-neutral watermark reconciler

    Low and high watermark state machine (WindowReconciler), chunked full-table dump orchestration, targeted primary-key repair, and restart-safe progress boundaries persisted in embedded H2.

  • Live adapters

    MySQL and PostgreSQL replication

    MySQL binlog (tested on 8.0, 8.4, 9.6) and PostgreSQL pgoutput (tested on 14 through 18) with an explicit table-scoped commit-visibility check and Docker-backed end-to-end convergence tests.

  • Inspection and ops

    Sinks, control plane, and Hydroscope

    NDJSON stream and file output, typed H2 inspector, idempotent JDBC target apply, no-op sink, a local HTTP control plane for triggering dumps and repairs, and the optional Rust/ratatui Hydroscope visualizer.

Study and verification scope: Built for study, auditing, and experimentation, not production CDC. dblog-impl implements the 2019/2020 DBLog algorithm (chunked snapshots and targeted key repair for existing keys) and does not implement the ABSENT / orphan-row repair extension. For production workloads using DBLog-based incremental snapshots, use Debezium or Apache Flink CDC.

How dblog-impl executes the watermark loop

Copying a table in bounded chunks while live changes stream from the transaction log creates a race: a slower chunk read can overwrite a newer change event. DBLog resolves that race deterministically by bracketing each chunk SELECT with two metadata writes, a low watermark (LOW) and a high watermark (HIGH), that land in the same transaction log as the captured tables.

  1. Stream live changes. Consume committed transaction-log events and forward them to the sink.
  2. Pause and write LOW. Pause log consumption and write a low-watermark row into the source metadata table.
  3. Select a bounded chunk. Read the next primary-key range (for example pk 41-43) into an in-memory buffer without emitting those rows yet (on PostgreSQL, after waiting for tracked table commits to become visible to the snapshot).
  4. Write HIGH and resume. Write the high-watermark row and resume reading the log from the pause position.
  5. Let the log win. Keep live log events in log order. If any in-window event targets the same table and primary key as a buffered chunk row, drop that buffered row. By HIGH, that key's last emitted state from the log is at least as new as the selected row.
  6. Flush survivors. When HIGH closes the window, omit the LOW and HIGH watermark markers and emit the reconciled window in logical order: in-window log events first, then surviving buffered rows in primary-key order. In dblog-impl, the runtime accumulates this window in memory, appends the reconciled batch to the sink at HIGH, and persists completed-chunk progress to H2 before acknowledging the source checkpoint.
DBLog watermark reconciliation diagram: log consumption pauses while LOW, a bounded chunk SELECT (pk=41, 42, 43), and HIGH run. On resume, UPDATE pk=42 on the same table lands inside the pause-to-HIGH collision window and drops buffered row 42 so the log wins. When HIGH closes the window, in-window log events and surviving rows pk=41 and pk=43 emit in logical order (survivors in key order), watermarks are omitted, and later live changes pass through.
Worked example: log consumption pauses while the connector writes LOW, buffers pk=41, 42, 43, and writes HIGH. On resume, UPDATE pk=42 on the same table lands inside the collision window and drops buffered pk=42. When HIGH closes the window, in-window log events and surviving rows 41 and 43 emit in logical order (survivors in key order), and watermarks are omitted from the output stream.
Want the full visual walkthrough? Read An introduction to DBLog for step-by-step animations covering log retention limits, why pre-DBLog snapshots stall or replay old values, how Debezium and Apache Flink CDC adopt DBLog, and the 2026 extension for removing orphan rows.

Code map and quick start

Every step of Algorithm 1 is mapped to its implementing class, fail-closed guard, and regression test in docs/PAPER_MAP.md, including explicit notes on paper deltas such as PostgreSQL commit visibility.

Reading path

Run locally (Java 21, Docker, Python 3.9+)

Start disposable MySQL and PostgreSQL fixtures, run an ALL_TABLES dump, apply live writes, and verify convergence:

git clone https://github.com/aandreakis/dblog-impl.git
cd dblog-impl
python3 scripts/demo/mysql_to_postgres.py

Verification suites from fast unit tests to the MySQL 8.0-9.6 and PostgreSQL 14-18 compatibility matrix (8 Docker images, 20+ min):

# fast unit tests (< 1 min)
./gradlew test

# live Docker convergence and repair scenarios
./gradlew e2eTestDocker

# MySQL 8.0-9.6 and PostgreSQL 14-18 (20+ min)
./gradlew compatibilityMatrix

Sources and related reading