A classic scheduled export compares table snapshots or updates by a “last modified” timestamp: such queries load the database and still miss deletes. CDC takes a different route — it picks changes from the transaction log or from triggers and delivers them to subscribers as a stream of events, so the sink data lags behind the source by seconds, not until the next overnight run.
How it works
The primary method is reading the transaction log: the WAL in PostgreSQL, the redo log in Oracle, the binlog in MySQL. The database writes every change there anyway — a CDC process reads this log and turns low-level entries into events. In PostgreSQL the mechanism is called logical decoding: the contents of the WAL are transformed into a stream of changes that applications can understand.
| Method | How it works | Cost |
|---|---|---|
| Transaction log | a separate process reads the WAL, redo log or binlog | barely loads the database, but requires privileges and server configuration |
| Triggers | a trigger on each table writes the change into a log table | slows down the very transactions that modify the data |
| Snapshot comparison | queries by timestamp or by checksums | misses deletes and same-frame overwrites, loads the database |
An event assembled from the log usually carries the minimum about what happened:
{ "op": "u", "source": {"table": "orders", "lsn": 3412054112}, "before": {"id": 42, "status": "NEW", "total": 1990}, "after": {"id": 42, "status": "PAID", "total": 1990} } Debezium and the typical pipeline
The open-source CDC tool is Debezium, a change data capture platform. Its connector attaches to the database, takes a consistent snapshot of the tables on the first run, then resumes the change stream from the snapshot point and produces an event for every insert, update and delete at the row level. The changes of each table are published to a separate Kafka topic, from which consumers read them.
The connector remembers the log position for each event and after a failure resumes from the same spot — events are not lost. The price of this reliability: on PostgreSQL the changes are consumed through a replication slot, which holds WAL segments until the consumer has read them.
Where it is used
- Synchronising caches and search indexes: Elasticsearch receives row changes almost immediately after the commit.
- Cache invalidation: an event about a row change tells all instances that it is time to re-read the record from the database.
- Audit: the change log answers who changed the data, when and how.
- Gradual migration between systems: changes keep flowing while the old database is still running.
Other meanings of CDC
The same abbreviation also appears outside IT — for example, the Centers for Disease Control, the US public health agency — but in IT, CDC usually means change data capture.
Sources
the term is written from these pagesVerified 9 Nov