Change Data Capture (CDC) is a technique for observing and capturing changes made to a database and delivering them as real-time events to downstream systems. Unlike polling-based methods, modern CDC is log-based, directly reading the database's internal transaction logs (e.g., PostgreSQL WAL, MySQL Binlog).
last_modified columns or triggers that slow down production writes.DELETE event from the transaction log.Debezium is the industry-standard open-source platform for CDC. It typically runs as a set of connectors within Kafka Connect.
dbserver1.inventory.orders).To capture changes from a PostgreSQL database, you must set wal_level = logical in postgresql.conf and provide a connector configuration.
JSON Configuration for Kafka Connect:
{
"name": "inventory-connector",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"tasks.max": "1",
"database.hostname": "postgres-db",
"database.port": "5432",
"database.user": "debezium",
"database.password": "dbz",
"database.dbname": "inventory",
"database.server.name": "dbserver1",
"table.include.list": "public.orders,public.customers",
"plugin.name": "pgoutput",
"publication.autocreate.mode": "filtered",
"slot.name": "debezium_fulfillment_slot",
"snapshot.mode": "initial"
}
}
A Debezium event contains a before and after block.
{
"op": "u",
"before": { "id": 1, "status": "PENDING" },
"after": { "id": 1, "status": "SHIPPED" },
"source": { "ts_ms": 1716200000000, "snapshot": "false" }
}
outbox table in the same transaction. CDC tracks only the outbox table, ensuring that the event is only published if the primary transaction succeeds.