The 30 second answer
On restart or rebalance the partition resumes from the last committed offset, so the message is processed again. That is at-least-once delivery. Effects must be idempotent: a dedupe table keyed by message or business id, upserts, or idempotent downstream APIs. Kafka transactions can give exactly-once inside Kafka, but external side effects still need idempotency. Committing before processing flips you to at-most-once and can lose work.
On restart/rebalance the partition resumes from the last committed offset → the message is processed again (at-least-once). Effects must be idempotent: dedupe table keyed by message/business id, upserts, idempotent downstream APIs. For Kafka→Kafka pipelines, transactions (read_committed + offsets committed in the producer transaction) give exactly-once within Kafka; external side effects still need idempotency. (Committing before processing flips it to at-most-once → loss.)
Alternate interview scenarios
"How do you handle Kafka duplicates, idempotency and ordering, and what does exactly-once really mean?"
This version asks for the full design, not just the crash case. Duplicates come from two places. On the producer side, a retry after a lost acknowledgement can write the same record twice, and enable.idempotence stops this within a partition. On the consumer side, a redelivery after a crash or rebalance processes the same record again, and the consumer must handle that with a dedupe table or idempotent writes. Kafka guarantees order only within one partition. So I use the entity id as the key, so that all events for one order land on the same partition. The Kafka docs warn that with several requests in flight and idempotence disabled, retries can reorder messages. Exactly-once in Kafka means a read-process-write pipeline inside Kafka with transactions and read_committed consumers. Once the effect is a database row or an email, I am back to at-least-once delivery plus idempotent effects.
Sources (2)
- Kafka docs — Message delivery semanticskafka.apache.org
- Kafka producer configs (enable.idempotence, max.in.flight.requests.per.connection)kafka.apache.org