Streaming Pipelines
Offset commits and duplicates in the warehouse, replays, exactly-once at the sink, CDC into tables, windows and watermarks.
10 questions
JuniorDebuggingVery commonA Kafka consumer loading batches into the warehouse loses rows after a crash — find and fix the bug
A Kafka consumer loading batches into the warehouse loses rows after a crash — find and fix the bug
Commit-then-insert loses the batch if the job dies in between; insert-then-commit re-inserts it after a crash. enable.auto.commit (default true, every 5 s) commits on a timer, not after the insert — disable it, commit after the insert, make the insert repeat-safe.
Common mistakes
- ✗Believing
enable.auto.commitwaits until the sink has stored the batch before it commits - ✗Treating write-then-commit as exactly-once and skipping a repeat-safe insert
- ✗Committing first to save progress, which turns every crash into silently missing rows
Follow-up questions
- →Which column would you use as the unique key to make the warehouse insert safe to repeat?
- →How does a consumer group rebalance in the middle of a long insert change this picture?
MiddleDesignVery commonA team streams order events from a Kafka topic into a PostgreSQL fact table and is asked for 'exactly-once' — no lost and no doubled orders, even across crashes and redeploys. Someone proposes turning on Kafka transactions and read_committed on the consumer and calling it done. The table is the reporting source of truth; the consumer may crash at any point between reading a batch and writing it; replays from an earlier offset must stay possible after a bug fix; load is about 2,000 events per second. Explain what Kafka's transactional exactly-once actually covers in this pipeline, then design the sink side so the table holds each order exactly once. Name the patterns you would use and what each one needs from the target table and from the consumer on start-up.
A team streams order events from a Kafka topic into a PostgreSQL fact table and is asked for 'exactly-once' — no lost and no doubled orders, even across crashes and redeploys. Someone proposes turning on Kafka transactions and read_committed on the consumer and calling it done. The table is the reporting source of truth; the consumer may crash at any point between reading a batch and writing it; replays from an earlier offset must stay possible after a bug fix; load is about 2,000 events per second. Explain what Kafka's transactional exactly-once actually covers in this pipeline, then design the sink side so the table holds each order exactly once. Name the patterns you would use and what each one needs from the target table and from the consumer on start-up.
Kafka transactions give exactly-once only Kafka to Kafka; the Postgres write is outside them. At the sink, either commit the offsets in the same DB transaction as the rows and seek to them on start, or upsert by a business key or (partition, offset) so a replay overwrites.
Common mistakes
- ✗Assuming Kafka's transactional exactly-once extends to an external database the consumer writes to
- ✗Storing offsets in the database but still letting the consumer resume from the group's committed offsets
- ✗Treating a plain INSERT as safe once offsets are committed after it, which still doubles a batch after a crash
Follow-up questions
- →What does a consumer with
isolation.level=read_uncommitted(the Java client's default) see from an aborted Kafka transaction? - →Which of the two sink patterns still works when the target is a warehouse with no multi-statement transactions?
JuniorTheoryCommonEvent time vs processing time — which clock should an hourly revenue report window on?
Event time vs processing time — which clock should an hourly revenue report window on?
Event time is when the purchase happened, stored in the record; processing time is when the job reads it. By processing time, an outage or a late mobile sync drops rows into the wrong hour and a replay re-buckets them — so reports window on event time.
Common mistakes
- ✗Bucketing by the moment the job read the row, so an outage piles hours of sales into one bucket
- ✗Assuming a replay reproduces the same hourly totals when windows run on processing time
- ✗Thinking event time removes the need to decide what to do with records that arrive late
Follow-up questions
- →Where does the event time come from in a Kafka record, and when can you not trust it?
- →How long should a streaming job wait for late events before it closes an hour?
JuniorTheoryCommonKafka cleanup.policy=delete vs compact — which topic can rebuild a table's current state?
Kafka cleanup.policy=delete vs compact — which topic can rebuild a table's current state?
delete drops old segments by age or size (retention.ms, default 7 days) — full history up to the limit. compact keeps at least the latest value per key, so offset 0 rebuilds current state, not history. A tombstone deletes a key and is purged after delete.retention.ms.
Common mistakes
- ✗Treating a compacted topic as a full change history, when compaction keeps only the latest value per key
- ✗Believing consumption deletes messages, when
deletedrops whole segments by time or size regardless of groups
Follow-up questions
- →What does a consumer that lags longer than
delete.retention.msmiss on a compacted topic? - →When would you set
cleanup.policy=compact,deleteon a CDC topic?
JuniorTheoryCommonTumbling, hopping and session windows — how do they differ, and which fits which report?
Tumbling, hopping and session windows — how do they differ, and which fits which report?
Tumbling: fixed, non-overlapping, one window per event — revenue per 5 min. Hopping: fixed size, advancing by less, so an event sits in size ÷ slide windows — 5 for a 5-min count each minute. Session: per key, closed by an inactivity gap — a visit.
Common mistakes
- ✗Expecting an event to be counted once in hopping windows, when it lands in size ÷ slide of them
- ✗Treating a session window as fixed-length rather than closed by a per-key inactivity gap
- ✗Using hopping windows for a revenue-per-interval report and summing overlapping totals
Follow-up questions
- →Which windows does an event at 12:07 land in for 10-minute hopping windows that advance every 5 minutes?
- →Why can two session windows of the same user merge into one when a late event arrives?
MiddleDebuggingCommonThe warehouse's daily event count runs 2–3% above the source after every deploy — find and fix the cause
The warehouse's daily event count runs 2–3% above the source after every deploy — find and fix the cause
A deploy restarts consumers and forces rebalances; batches inserted but not yet committed are re-read by the partition's new owner and inserted again. Copies per (partition, offset) cluster at deploy times. Fix it at the sink — a unique key plus upsert or MERGE.
Open full question →Common mistakes
- ✗Expecting a commit in the partition-revoke callback to close the window, when a crash or a killed pod still skips it
- ✗Blaming producer retries, when a retried send lands under a new offset and these copies share one (partition, offset)
- ✗Deduplicating in a dashboard filter instead of making the load itself reject or overwrite repeats
Follow-up questions
- →Why does committing in the partition-revoke callback narrow the duplicate window but not close it?
- →How does Kafka's static group membership (
group.instance.id) change the number of rebalances per deploy?
MiddleCodeCommonA loader bug corrupted three days of warehouse data — replay them from Kafka without duplicates
A loader bug corrupted three days of warehouse data — replay them from Kafka without duplicates
Stop the group, run kafka-consumer-groups.sh --reset-offsets --to-datetime 2026-11-05T00:00:00.000 — --dry-run plans, --execute applies. Retention caps how far back you go. The reload must replace rows from Nov 5 on (delete + insert or MERGE), or it appends duplicates.
Common mistakes
- ✗Resetting offsets while group members are still active, which the tool refuses for a live group
- ✗Expecting
auto.offset.resetto rewind a group that already has committed offsets - ✗Replaying into an append-only load and cleaning up only the broken days, while the replay re-reads everything up to now
Follow-up questions
- →When would you replay into a new
group.idand a side table instead of rewinding the production group? - →What does a replay from offset 0 return on a compacted topic, and why is that not the full history?
MiddleTheoryCommonWatermark for events 4, 8, 6, 12, 10, bound 5: when does window [0, 5) close and what happens to late events?
Watermark for events 4, 8, 6, 12, 10, bound 5: when does window [0, 5) close and what happens to late events?
A watermark says no events older than T are expected: max event time seen minus the bound — −1, 3, 3, 7, 7 (Flink takes 1 ms more off), so window [0, 5) closes at event 12. A late event is dropped by default (Flink lateness 0), sent to a side output, or fixed in batch.
Common mistakes
- ✗Treating a watermark as a guarantee that no later event will come, when it is only a heuristic bound
- ✗Expecting a late event to update its closed window by default, when Flink drops it unless allowed lateness or a side output is set
- ✗Computing the watermark from the minimum event time or from wall-clock time instead of the maximum seen minus the bound
Follow-up questions
- →Why does one idle Kafka partition stop event-time windows from firing in the stream processor Flink?
- →How does the streaming engine Spark Structured Streaming treat data later than its watermark threshold?
SeniorDesignCommonDesign change data capture from a 200-table PostgreSQL 18 OLTP database into an analytics warehouse, using Debezium and Kafka. Lag from commit to warehouse must stay under 60 seconds and the extra load on the source must stay small. The warehouse needs a current-state copy of every table and an append-only change history for a few of them. Hard deletes in the source must reach the warehouse. One table is 2 TB and cannot be locked or held in one long snapshot for hours. Explain how the pipeline loads the rows that already exist and then follows new changes without a gap, how topics are keyed and what ordering that gives, how deletes travel, what delivery guarantee you get after a connector or broker failure, how the warehouse applies changes so that duplicates and replays do no harm, how the 2 TB table is brought in, and what you monitor on the source.
Design change data capture from a 200-table PostgreSQL 18 OLTP database into an analytics warehouse, using Debezium and Kafka. Lag from commit to warehouse must stay under 60 seconds and the extra load on the source must stay small. The warehouse needs a current-state copy of every table and an append-only change history for a few of them. Hard deletes in the source must reach the warehouse. One table is 2 TB and cannot be locked or held in one long snapshot for hours. Explain how the pipeline loads the rows that already exist and then follows new changes without a gap, how topics are keyed and what ordering that gives, how deletes travel, what delivery guarantee you get after a connector or broker failure, how the warehouse applies changes so that duplicates and replays do no harm, how the 2 TB table is brought in, and what you monitor on the source.
Debezium snapshots existing rows, then tails the WAL from the recorded LSN; topics per table keyed by PK keep per-key order, and a delete comes as a delete event plus tombstone. Delivery is at-least-once: stage and MERGE by PK, keeping the highest LSN. Snapshot the 2 TB table incrementally; watch slot lag.
Common mistakes
- ✗Assuming log-based CDC needs no initial snapshot, when the WAL holds only recent changes, not the existing rows
- ✗Appending change events as-is, when at-least-once delivery after a fault replays some of them
- ✗Starting a 2 TB table with one long blocking snapshot instead of chunked incremental snapshots interleaved with streaming
Follow-up questions
- →What happens to the source database's disk if the Debezium connector stops reading its replication slot for a day?
- →How would you build the append-only change history from the same topics without double-counting replayed events?
SeniorDebuggingOccasionalA Spark Structured Streaming job grows state until OOM and writes repeated window rows — find the causes
A Spark Structured Streaming job grows state until OOM and writes repeated window rows — find the causes
No withWatermark: every window's state is kept forever and append mode is refused; update re-emits changed windows, and appending them adds rows. foreachBatch is at-least-once, the checkpoint never dedupes topic copies — add a watermark, dropDuplicatesWithinWatermark, append mode, an upsert by key.
Common mistakes
- ✗Believing append mode silently emits nothing without a watermark, when Spark rejects the query at start
- ✗Expecting the checkpoint to deduplicate records the producer wrote to the topic twice
- ✗Restarting a query with a newly added watermark or dedup on the old checkpoint, which Spark does not allow for changed stateful operators
Follow-up questions
- →Why does complete output mode never drop state, even with a watermark set?
- →How would you use
batch_idto make a non-transactional sink safe against a re-run micro-batch?