Skip to content
tezvyn:
Menu

Implement CDC from OLTP to warehouse

Source: interviewMediumHow cards are made

Summary

low-impact replication of inserts, updates, and deletes.

Key points

contrast log-based CDC with query-based timestamp polling, cover deletes and load on source, then pick log-based for minimal impact.

What's really being asked

The question checks whether you understand the mechanics of capturing inserts, updates, and deletes from a live OLTP system while keeping its performance untouched, and whether you grasp the real trade-offs between approaches.

The full answer

Describe at least two methods. Query-based CDC polls the source, either by selecting rows where an updated_at timestamp exceeds the last run or by diffing full snapshots. It is easy to set up and database-agnostic, but it adds read load, has latency tied to poll frequency, and crucially cannot see hard deletes because a deleted row simply vanishes. Log-based CDC reads the database transaction log such as the Postgres WAL or MySQL binlog, often via Debezium and a stream like Kafka. It captures every committed change including deletes, imposes almost no extra query load on the source, and gives low latency, at the cost of operational complexity, log-retention management, and per-engine connectors. For minimal source impact, recommend log-based, landing a change stream that the warehouse merges.

The mistakes people make

Proposing only timestamp polling and forgetting it misses physical deletes, running heavy full-table scans on the production database, or ignoring how out-of-order or duplicate change events are handled downstream.

What usually comes next

How do you handle schema changes in the source? How do you guarantee exactly-once or at-least-once delivery and idempotent merges? How do you bootstrap an initial snapshot before streaming incremental changes?

A concrete example

For a Postgres orders table, you enable logical replication, point Debezium at the WAL, and stream change events to Kafka. Each event carries the operation type, so a delete arrives as an explicit tombstone. The warehouse applies a merge that upserts inserts and updates and removes deleted keys, keeping the warehouse copy accurate without ever scanning the live table.

Interview question

Compared with log-based CDC, what is the key weakness of query-based CDC that polls an updated_at timestamp?

  • a.It requires reading the database transaction log
  • b.It always has lower latency than log-based CDC
  • c.It cannot capture new inserts
  • d.It silently misses rows that were hard-deleted from the sourceCorrect
Why?

A physically deleted row leaves no timestamped trace, so polling cannot detect it; log-based CDC sees the delete in the log. Query-based CDC does capture inserts and does not read the transaction log.

Just read this? Test yourself on what you have been reading.

Read the original → datacamp.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles