Design a CDC pipeline that replicates a busy PostgreSQL database into Iceberg or Delta tables, including updates and deletes. What are the tricky parts?
What the interviewer wants to hear
- Initial snapshot plus streaming changes without gaps or duplicates
- Debezium reading the WAL into Kafka, keyed by primary key
- Apply changes with MERGE using the log sequence number to keep order and dedupe
- Handle deletes, tombstones and schema changes
- Manage small files and delete files with compaction and maintenance
- Monitor lag and run reconciliation against the source
Model answer
I would run Debezium against PostgreSQL logical replication. It takes a consistent initial snapshot and then streams WAL changes into Kafka topics keyed by primary key, so changes for one row stay in order. A Spark or Flink job reads micro-batches, keeps only the latest change per key within each batch using the LSN, and MERGEs into an Iceberg or Delta table: updates overwrite, inserts add, and delete events remove rows or set a soft-delete flag. Using the LSN in the merge condition makes replays idempotent and stops an older event from overwriting a newer one. Schema changes flow through a schema registry, and I allow additive changes automatically but alert on breaking ones. Frequent merges create many small files and delete files, so I schedule compaction and snapshot expiry. Finally I monitor replication slot lag, because a stuck slot fills the source disk, and I run periodic count and checksum reconciliation.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Data Engineer questions
- Design a data platform for a fast-growing startup with 20 data sources and a small team. What would you choose and why?
- Explain at-most-once, at-least-once and exactly-once processing, and how you achieve effectively-once results in practice.
- A user asks to delete all their personal data. Your data is spread across a data lake, warehouse and backups. How do you handle it?
- How do you choose partitioning and clustering for a very large table? What can go wrong?
- The CEO's revenue dashboard showed wrong numbers for two days before anyone noticed. How do you fix this and prevent it from happening again?
- Design a pipeline that ingests 200,000 clickstream events per second and powers both a real-time dashboard and daily analytics.
- You must migrate a company from an on-premise warehouse to Snowflake or BigQuery without breaking hundreds of reports. How would you plan it?
- Leadership asks you to cut the cloud warehouse bill by 40 percent without hurting the business. What do you do?
- A metric definition changed and you must backfill two years of a large fact table while the daily pipeline keeps running. How do you do it safely?