patterntypescriptModerate
CDC with Debezium: stream database changes to Kafka without dual writes
Viewed 0 times
Debezium 2.x, PostgreSQL 12+
cdcchange data capturedebeziumpostgres wallogical replicationkafka connecttombstone
Error Messages
Problem
Publishing events from application code requires dual writes (DB + broker) which can desynchronise. Polling the DB for changes is inefficient and misses deleted rows.
Solution
Use Debezium to tail the Postgres WAL (write-ahead log). Every INSERT/UPDATE/DELETE is captured as a Kafka event without any application code changes.
{
"name": "orders-connector",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"database.hostname": "postgres",
"database.port": "5432",
"database.dbname": "mydb",
"table.include.list": "public.orders",
"topic.prefix": "mydb"
}
}Why
The WAL is the authoritative record of all changes. CDC reads it as a stream, providing low latency, no polling overhead, and no risk of missed rows including deletes.
Gotchas
- Postgres must have
wal_level = logical— verify this before enabling Debezium in production - The initial snapshot can be large — plan for it; use incremental snapshots for large tables
- Tombstone records (null value) represent deletes in Kafka — consumers must handle them
- WAL replication slots hold WAL files until Debezium ACKs them — a stalled connector fills the disk
Context
Teams wanting to emit events from an existing database without modifying application code
Revisions (0)
No revisions yet.