Skip to content
Prompt Words
History Member

Change data capture (CDC)

Also called: CDC.

A connector reads every committed change (insert, update, delete) from the database's own log and publishes each one as an event, for example to Kafka. It saves how far it has read, and the database keeps its log from that point on (in Postgres, while the connector's replication slot is kept), so after a stop it carries on and misses nothing. Other systems, like a search index or a cache, stay in sync by reading the events, with no change to the app's code.

Update a customer and watch the change travel from the database log to the search index. Stop the connector, update twice, then press Stop the connector again to restart it.

Updates: 0 · Connector position: 101 · Waiting in the log: 0

Customer 7 lives in Lisbon. The connector has read the log up to entry 101.

    Connector running

    Say it in a prompt

    Stream changes from the Postgres customers table to the search index with Debezium. Set wal_level=logical, give the connector its own replication slot with the pgoutput plugin, and publish change events to the Kafka topic shop.public.customers, keyed by customer id. A sink applies each event to the customers index in order. After a stop the connector resumes from its saved position; alert when the slot holds back more than 10 GiB of WAL.

    Vague vs precise prompt

    Vague prompt

    keep the search index up to date with the customers table

    Typical resultAdds a call to the search service after each save in the app. Changes made by other code paths, scripts or manual SQL never reach the index, and when the search service is down the update is simply dropped, so the index slowly drifts away from the database.

    Precise prompt

    Use change data capture: a Debezium Postgres connector reads the customers table's changes from the WAL through a replication slot and publishes them to the Kafka topic shop.public.customers; a sink applies them to the search index in order. After a stop, resume from the saved position.

    Typical resultEvery committed change reaches the index, including ones from scripts and manual SQL, with no change to the app. When the connector or the index is down, the changes wait in the log or in Kafka and are applied in order when it comes back.

    Seen on

    • Debezium docs: The PostgreSQL connector uses logical decoding and a replication slot to read committed changes from the write-ahead log, and sends one change event per row insert, update or delete to a Kafka topic per table. After a stop it continues reading the WAL where it left off.
    • PostgreSQL docs: Logical decoding turns the write-ahead log into a stream of row changes. A replication slot keeps the WAL its consumer hasn't read yet, so it can pick up where it stopped; after a crash some recent changes may be sent again.
    • PostgreSQL docs: Every change is written to the write-ahead log before the table files, and a transaction counts as committed once its log records are on disk.

    You might describe it as

    • stream every database change out as events
    • keep the search index in sync without touching the app
    • read the database's own log of changes

    Not to be confused with

    • Transactional outbox

      Change data capture reads every committed change from the database's log, whether or not the app meant to announce it; an outbox is the app writing an event row on purpose, in the same transaction as the change.

    • Webhook

      A webhook is one app calling another app's URL when something happens; change data capture reads every committed change from the database log, even ones no code announced.