Streaming: Kafka
Kafka is the event log the warehouse reads in near real time: orders, clicks, row changes from an OLTP database. A data engineer needs more than knowing what a partition and an offset are. What matters is what ends up in the table after a crash, a deploy, or a re-read, since any of them can lose rows or write them twice.
In an interview almost every question comes down to four things. What a topic keeps and how far back you can re-read (retention and compaction). In which order the consumer writes rows and commits offsets, and what a rebalance does to an uncommitted batch. Why Kafka's exactly-once stops at Kafka's edge and how to make the sink safe against repeats. Which clock windows are built on and when a window can close (event time, watermarks). CDC is a topic of its own: how Debezium turns the PostgreSQL WAL into a change stream and how that stream is merged into a warehouse table.
Versions in the text: Kafka 4.4, Flink 2.3, Spark 4.3, Debezium 3.7, PostgreSQL 18. Where a default changed, the version is named.
Topic map
- Kafka for data engineers — topics, partitions and offsets, consumer groups, retention versus compaction, and what of it shows in the warehouse.
- Delivery semantics — commit and insert order, rebalances and double counting, the idempotent producer, transactions and
read_committed, exactly-once up to the sink, idempotent writes. - Event-time windows — event time versus processing time, tumbling, sliding and session windows, watermarks and late events, idle sources in Flink, watermarks and output modes in Spark Structured Streaming.
- CDC pipelines — Debezium snapshot and streaming, per-key ordering, merging by primary key and LSN in the warehouse, replays.
Common traps
| Mistake | Consequence |
|---|---|
| Committing the offset before the warehouse insert | A crash between the commit and the insert silently loses the batch |
Leaving enable.auto.commit=true and assuming it commits after the write | It commits on a timer, not after the insert, so rows are lost or doubled |
Writing into the warehouse with a plain INSERT | Every rebalance and every re-read adds copies |
| Believing Kafka transactions give exactly-once for a PostgreSQL write | The external database is outside the Kafka transaction; duplicates remain |
| Building a report on processing time | An outage or a late sync drops sales into the wrong hour |
| Reading a compacted topic as full history | Compaction keeps the latest value per key, not every change |
| Appending CDC events to a table as they come | Re-delivery after a fault duplicates changes |
Interview relevance
Streaming is asked about to check whether a candidate sees the consequences for the data, not only how the broker works. A strong answer names the point where a row can be lost or doubled and the way to make it harmless: "the batch is inserted, the offset is not committed, after a rebalance the partition's new owner reads it again, so the sink writes with a MERGE by key."
Typical checks:
- The insert-then-commit order and why it still needs an idempotent write.
- Where the extra rows after a deploy come from and how to prove it by
(partition, offset). - What Kafka's exactly-once covers and how to extend it to the table.
- Replaying past days by resetting offsets and overwriting the range.
- Event time, watermarks, and what happens to a late event.
- CDC: a snapshot with no gap to streaming, per-key order, deletes, and merging by LSN.
Common wrong answer: "Turn on Kafka transactions and read_committed and the table gets exactly-once." In fact a Kafka transaction atomically commits only writes to topics and the group's offsets. The PostgreSQL write is outside it, so exactly-once is built at the sink: store the offsets in the same transaction as the rows, or write by key so a repeat overwrites the row.