What is change data capture (CDC)?

Change data capture (CDC) is a way of detecting every insert, update and delete in a database and streaming those changes to other systems, usually by reading the database's transaction log.

Also called CDC, log-based CDC, database change streamingUpdated

Most data pipelines start with a nightly query: "give me every row changed since yesterday". That misses deletes, puts load on the production database and leaves reports a day old. Change data capture takes a different route. It reads the changes the database already records for its own recovery and turns each one into an event.

Three ways to capture changes

  • Log-based CDC. Read the database's transaction log: the write-ahead log (WAL) in PostgreSQL, the binlog in MySQL, the transaction log in SQL Server. It catches every change, including deletes, in commit order, with little extra load. This is the default choice.
  • Query-based CDC. Poll for rows where updated_at is newer than the last run. Simple, but it misses hard deletes and any update that forgets to set the timestamp.
  • Trigger-based CDC. Database triggers copy each change into a side table. It works everywhere but slows down every write.

How log-based CDC works in practice

For PostgreSQL, you set wal_level = logical and create a publication and a replication slot. A connector such as Debezium reads the slot through logical decoding (the pgoutput plug-in), takes an initial snapshot of existing rows, then streams changes. It usually publishes them to Kafka, one topic per table. SQL Server has CDC built in: you enable it with sys.sp_cdc_enable_db and then per table, and it fills change tables you can read.

Example: a Debezium change event

A customer upgrades their plan. Debezium emits an event with the row before and after the update:

{
  "op": "u",
  "before": { "id": 4182, "plan": "basic", "mrr_paise": 99900 },
  "after":  { "id": 4182, "plan": "pro",   "mrr_paise": 249900 },
  "source": { "table": "subscriptions", "lsn": 2369384712 },
  "ts_ms": 1795240800000
}

op is c for insert, u for update, d for delete and r for rows read during the snapshot. Consumers then:

  • upsert the row into a warehouse or lakehouse table, keyed on id, so analytics are minutes old rather than a day
  • update a search index
  • trigger a "plan upgraded" email

Each consumer must be idempotent, because CDC pipelines deliver at least once.

What CDC is used for

  • Near-real-time analytics in place of nightly ETL batches.
  • Legacy migration. Keep a new system in sync with an old database while you move features across with the strangler fig pattern.
  • Cache and search sync, so Redis or Elasticsearch never drift from the source.
  • Audit trails of who changed what.

CDC vs the outbox pattern

CDC exposes your table structure. Rename a column and every consumer breaks. For events between services, the transactional outbox is often better. The service writes a deliberate event to an outbox table, and CDC streams only that table. You keep the reliability of reading the log without publishing your internal schema.

"Change Data Capture" is also the name of a Salesforce feature. It publishes events when Salesforce records are created, updated, deleted or undeleted. The idea is the same, but you subscribe to Salesforce's event channels and don't read a database log.

Common mistakes

  • Leaving a replication slot unconsumed. PostgreSQL keeps WAL for it, and the disk fills up.
  • No schema registry, so a column change in the source silently breaks the stream.
  • Using CDC where a nightly batch would do. Streams cost more to run and debug.

See how CDC fits alongside Kafka in Kafka vs RabbitMQ vs SQS.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call