DBLog Guide · Paper (arXiv) · Netflix Tech Blog · Companion Essay
A Java 21 reference implementation of DBLog, by its creator Andreas Andreakis. DBLog is a Change-Data-Capture (CDC) algorithm that copies the full state of a source database alongside live changes, without blocking writes or stalling the change event flow. You can run the published algorithm here against real MySQL (binlog) and PostgreSQL (pgoutput) streams and follow every step in Java.
DBLog originated at Netflix and was published in the Netflix Technology Blog post (2019) and the DBLog paper (2020). Its watermarked-chunk mechanism later shaped incremental snapshots in Debezium and Apache Flink CDC. If you want a visual introduction first, read An introduction to DBLog. The dblog-impl overview hosts the web companion summary and recorded Hydroscope walkthrough, and I Vibe Coded My Old Netflix Project covers how the codebase was built with coding agents.
Scripted showcase replay of DBLog watermark windows reconciling change-log events with bounded chunk reads into one ordered output stream, shown in the Hydroscope TUI.
The core problem DBLog solves is copying existing rows from a live table in small chunks without blocking writes or stalling the change stream.
This repository puts the watermark loop directly in Java so engineers can read it, run it against MySQL and PostgreSQL in Docker, and see how checkpointing and crash recovery work around open windows. docs/PAPER_MAP.md maps each step of Algorithm 1 to its implementing class, guard checks, and tests, along with places where this codebase departs from the 2020 paper.
Treat this as a reference implementation for study and testing. For production CDC with DBLog-style incremental snapshots, use Debezium or Apache Flink CDC.
A chunked snapshot races with concurrent writes to the same keys. DBLog resolves that race in six steps.
- Stream live changes. Keep consuming committed source-log transactions.
- Open the window. Pause log reading and write a low watermark (
LOW) row into the source metadata table. - Read one chunk. Select a bounded primary-key range into an in-memory buffer.
- Close the read. Write a high watermark (
HIGH) row. - Reconcile on resume. Resume reading from the pause point until
HIGH. Stream each committed in-window log transaction to the sink in log order while pinning the source checkpoint, and remove any buffered chunk row whose table and primary key match one of those log events. - Flush and checkpoint. When
HIGHappears on the log stream, close the window, flush the surviving chunk rows in primary-key order (with watermark markers omitted), and persist completed-chunk progress before acknowledging the source checkpoint.
Buffered chunk rows are held back until HIGH because every change the chunk
read saw committed before HIGH. Any same-table collision event arrives in log
order no later than HIGH, so by HIGH, the key's last emitted state from the
log is at least as new as the row from the SELECT. In dblog-impl, each
committed in-window log transaction streams incrementally to the sink while the
source checkpoint stays pinned until HIGH completes and flushes the surviving
chunk rows. On PostgreSQL, the chunk read also
waits until tracked transactions already read from the log that changed the
table being read are visible to new snapshots
(commit visibility).
For the formal algorithm and motivation, read
the paper and the
Netflix Technology Blog post.
In this example, log consumption pauses while the connector writes LOW, selects chunk pk=41, 42, and 43 into memory, and writes HIGH. On resume, in-window log transactions stream to OUTPUT in log order with the source checkpoint pinned, and same-table UPDATE pk=42 evicts buffered pk=42 so the key's final state from the log by HIGH is at least as new as the selected row. When HIGH arrives, surviving chunk rows pk=41 and pk=43 flush in key order, watermark markers are omitted, and the completed chunk and checkpoint commit.
Prerequisites:
- Java 21
- Docker, for demos and Docker-backed tests
- Python 3.9+, for
scripts/demo/*.py - Rust stable only if you want to build Hydroscope
Run the shortest end-to-end demo:
python3 scripts/demo/mysql_to_postgres.pyOn Windows:
py -3 scripts/demo/mysql_to_postgres.pyThe demo starts disposable local fixtures, runs DBLog on the host, submits an
ALL_TABLES dump through the local HTTP control plane, verifies the initial
copy, applies live source changes, and verifies convergence again. Logs are
written under build/demo/<demo-name>/runtime.log. Isolated demo fixture
containers stop on exit. Set DBLOG_DEMO_KEEP_CONTAINERS=1 to leave
them running for inspection.
The first run pulls the Docker images and takes a few minutes on a cold cache.
When it passes, it prints Initial dump converged., Live changes converged.,
and Demo succeeded. before exiting 0.
Useful verification commands:
./gradlew test # fast unit tests
./gradlew integrationTest # adapter and state integration tests
./gradlew integrationTestDocker # Docker-backed adapter integration tests
./gradlew e2eTest # inspection-mode recovery/drift/failure scenarios
./gradlew e2eTestDocker # live Docker convergence and repair scenarios
./gradlew compatibilityMatrix # mysql:8.0/8.4/9.6 and postgres:14-18Wall times vary by hardware and Docker cache state. The test lane finishes
in well under a minute, integrationTest and e2eTest run in a few minutes,
and the Docker-backed lanes (integrationTestDocker, e2eTestDocker) take
longer because they spin up database containers. compatibilityMatrix takes
20+ minutes because it runs the full 8-image matrix across MySQL and
PostgreSQL.
The fixture credentials are disposable and bind database ports to 127.0.0.1.
Do not expose them on an untrusted network.
| Area | Included |
|---|---|
| Runtime | Java 21, Spring Boot, Gradle |
| Sources | MySQL binlog streaming, PostgreSQL pgoutput logical replication |
| Source-image matrix | mysql:8.0, mysql:8.4, mysql:9.6 / postgres:14 through postgres:18 |
| Sinks | NDJSON stream/file, typed H2 inspection sink, JDBC target apply for PostgreSQL/MySQL, no-op |
| State | Embedded H2 checkpoints, schemas, requests, and chunk progress |
| Control plane | Local HTTP API for status, metrics, request submission, and inspection |
| Verification | Unit, integration, Docker-backed e2e, and source-version matrix tests |
| Visualization | Optional Hydroscope Rust TUI over an educational tap stream |
| Start here | Why |
|---|---|
| docs/PAPER_MAP.md | Algorithm 1 step-by-step map to classes, safety checks, tests, and paper deltas |
| WindowReconciler.java | Low/high watermark state machine and collision handling |
| DefaultDumpWindowCoordinator.java | Opens chunk windows and persists restart boundaries |
| DefaultTargetedRepairCoordinator.java | Targeted primary-key repair through the same window machinery |
| RuntimeRequestPump.java | Interleaves live streaming with queued operator requests |
| docs/OPERATION.md | Configuration, boot modes, sinks, and operational behavior |
| docs/CONTROL_PLANE.md | HTTP API shape and request lifecycle |
| docs/adapters/mysql.md / docs/adapters/postgres.md | Source-specific preconditions and limits |
Coding agents should also read AGENTS.md.
Two additional Python demos cover NDJSON output and PostgreSQL-to-MySQL sync
using the same fixture flow as mysql_to_postgres.py above:
python3 scripts/demo/mysql_to_ndjson.py
python3 scripts/demo/postgres_to_mysql.pyIf you opt in with DBLOG_DEMO_ADOPT_EXISTING_COMPOSE=1 to reuse a database
stack started manually with docker compose -f ops/docker/compose.yml up -d,
the demo leaves that stack running. Stop it with
docker compose -f ops/docker/compose.yml down -v. In general a demo removes
its containers and volumes on exit only when the compose project had no
containers before that run; a project that already had containers is left
running as a whole, including any container the run added to it.
To run the runtime manually against the Docker fixtures:
docker compose -f ops/docker/compose.yml up -d
./gradlew bootRun \
--args="--spring.config.additional-location=file:./ops/docker/examples/local/mysql-to-postgres/application.properties"With the local control plane enabled:
curl -sS http://127.0.0.1:8085/api/v1/runtime/status
curl -sS -X POST http://127.0.0.1:8085/api/v1/requests \
-H 'Content-Type: application/json' \
-d '{"scope":"ALL_TABLES"}'If 8085 is in use, pass --dblog.control-plane.port=<port> to bootRun (or set
DBLOG_CONTROL_PLANE_PORT=<port> for the Python demos, which otherwise
auto-pick a free port and report it on stderr). Hydroscope live mode then
needs --url http://127.0.0.1:<port>/api/v1/tap/stream to match.
For Docker-packaged examples and fixture reset details, see ops/docker/README.md.
dblog-impl implements the 2019/2020 DBLog algorithm (chunked snapshots and targeted primary-key repair for existing keys) and omits the ABSENT orphan-row repair extension.
A few constraints are built into the runtime:
- It runs as a single process on one host backed by embedded H2, with no HA, leader election, or distributed state store.
- The HTTP control plane supports submitting and inspecting requests, not pausing, resuming, or canceling them.
- Sources are MySQL and PostgreSQL, and sinks are NDJSON, H2 inspection, JDBC target apply, and no-op.
- PostgreSQL
TRUNCATEon a captured table is not captured, so truncated rows stay in the sink (details). - Schema changes do not stream through automatically. There is no DDL replay or schema-history topic, so incompatible changes fail closed and require a fresh dump.
- Delivery is at-least-once. JDBC apply uses idempotent primary-key upserts and deletes, while NDJSON consumers have to dedupe on replay.
Hydroscope is a self-contained Rust/ratatui visualizer of the DBLog watermark algorithm. Once built, the bundled demo scenarios replay fixed windows with no database, Java, or Docker, so you can watch chunk reads, in-window log events, and collision-driven row drops step by step:
cd ops/tap-tui
cargo build --release --bin hydroscope
./target/release/hydroscope --scenario showcaseThe same binary attaches to a live DBLog process when started without a
scenario flag (./target/release/hydroscope). See
ops/tap-tui/README.md for live-mode setup and the
Hydroscope walkthrough
for annotated screenshots.
The tap is off by default and meant only for local teaching runs, because a slow subscriber stalls the DBLog pump thread via TCP backpressure (docs/CONTROL_PLANE.md).
An introduction to DBLog
Conceptual guide to DBLog, incremental snapshots in Debezium and Apache Flink CDC, and sink repairs
dblog-impl overview
Project page, recorded Hydroscope walkthrough, and code map on aandreakis.com
DBLog: A Watermark Based Change-Data-Capture Framework
Andreas Andreakis and Ioannis Papapanagiotou · arXiv · 2020
DBLog: A Generic Change-Data-Capture Framework
Andreas Andreakis and Ioannis Papapanagiotou · Netflix Technology Blog · 2019
There is no feature roadmap and no support commitment. Please do not open feature requests, new adapter or sink proposals, or HA asks, though small bug reports and targeted fixes inside the current scope are welcome (CONTRIBUTING.md). Forks and private modifications are welcome under the MIT License.
Built from the published DBLog paper and Netflix Technology Blog post. This is an independent open-source implementation, not Netflix's production codebase, and is not affiliated with, endorsed by, or sponsored by Netflix.
Released under the MIT License. See LICENSE, NOTICE, and PATENTS.md for license terms, provenance, and third-party patent context.
