Skip to the page

Streaming and CDC · senior

Delivery guarantees, idempotent sinks and state

Exactly-once stops at the edge of the system that supports it. Real pipelines use at-least-once delivery with idempotent writes, stable checkpoints and bounded state.

The notes

What you must know

  • At-most-once: commit the offset, then process; a crash loses messages. At-least-once: process, then commit; a crash replays and duplicates. Exactly-once: the effect happens once, even with retries and crashes.
  • Inside Kafka: the idempotent producer (on by default since Kafka 3.0) removes duplicates from producer retries per partition. Transactions make read-process-write between topics atomic. Readers use isolation.level=read_committed.
  • Exactly-once stops at Kafka's edge. An outside sink must be idempotent (upsert by key) or store offsets in the same transaction as the data.
  • Spark: a replayable source, offsets in the checkpoint and a transactional sink (each micro-batch is one Delta or Iceberg commit) give exactly-once into the table. foreachBatch into JDBC is at-least-once unless the write is a MERGE by key or tags the batch id.
  • Most pipelines are effectively once: at-least-once plus idempotent writes or deduplication by event id.
  • Duplicates after a redeploy: check the checkpoint path and starting offsets. A checkpoint path that includes the release number starts a new query with no checkpoint. Keep one stable path per query.
  • Clean up with a dry run on a copy: find duplicates by payment_id, delete the second copies or rewrite the dates with a deduplicated version, and check totals. Resetting the checkpoint is not a fix.
  • dropDuplicates with no watermark keeps every id ever seen in state, so state and batch time grow every day. Use withWatermark plus dropDuplicatesWithinWatermark, or move state to the RocksDB state store.
  • Changing a stateful operation is usually not compatible with the old checkpoint. Start a new checkpoint from a known offset and make the sink idempotent so the overlap does not duplicate.

The red pen

Common traps: mistake → fix

  • Mistake: Turn on exactly-once in the config and you are done

    Fix: it covers Kafka, not writes to Postgres.

  • Mistake: Reset the checkpoint to fix duplicates

    Fix: that can reprocess data and cause more.

  • Mistake: dropDuplicates on a stream is free

    Fix: it keeps state for ever without a watermark.

Easy to hard

Questions interviewers ask, easy to hard

  1. What do at-most-once, at-least-once and exactly-once mean?
  2. Where does Kafka's exactly-once stop?
  3. After a redeploy there are 2 lakh duplicate payments. What happened?
  4. A streaming dedup job gets slower every day. Why?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview