Change data capture

Log-based CDC (Debezium) vs query-based polling, initial snapshot + stream, ordering per key, applying upserts/deletes to the lakehouse. The standard OLTP-to-analytics bridge.

About 28 min read3-question knowledge check

The mental model

Change data capture is **reading a database's diary instead of interrogating it every hour**. Every transactional database already keeps a durable, ordered log of every change it makes — Postgres's WAL, MySQL's binlog, Oracle's redo — because that log is how it recovers from a crash and replicates to standbys. CDC quietly tails that same log and turns each committed change into an event: "order 5192 was updated, status went from PENDING to SHIPPED, at this log position." Instead of polling WHERE updated_at > last_run (which misses deletes, misses in-place updates that don't touch the timestamp, and hammers the source), you get every insert, update, and delete, in commit order, with near-real-time latency, and almost no load on the source.

The analogy that sticks: two ways to keep a copy of a busy shop's inventory. Query-based polling is walking in every hour and re-counting the shelves — you see the current state but never *what changed* (was that missing item sold or stolen?), you miss anything that changed and changed back between visits, and you disrupt the shop each time. Log-based CDC is reading the shop's transaction receipts as they print — every sale, return, and restock, in order, without touching the shelves. You reconstruct inventory perfectly and you know the history of every change, including deletes, which a re-count can never tell you.

Why this is the standard OLTP-to-analytics bridge: analytics needs data from the transactional systems, but you can't run heavy analytical queries against the production OLTP database, and nightly dumps are stale and expensive. CDC continuously mirrors the OLTP tables into the lakehouse/warehouse with low latency and full change history — it's how "the source of truth lives in Postgres, the analytics live in the lakehouse" is actually implemented.

The one idea that makes CDC correct: a CDC pipeline is initial snapshot + continuous stream, ordering guaranteed per key, applied to the target as idempotent upserts and deletes. Every hard part — consistency between snapshot and stream, exactly-once feel, handling deletes — is a consequence of getting those pieces right.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision