"Explain how Kafka guarantees at-most-once, at-least-once, and exactly-once delivery."
Delivery guarantees are the core Kafka interview question because every messaging system forces this tradeoff, and most candidates misunderstand "exactly-once". Interviewers probe whether you know the producer and consumer sides both have to cooperate to achieve the guarantee.
Start with the definitions: at-most-once means 0 or 1 delivery (may lose messages, never duplicates); at-least-once means 1 or more (never lose, may duplicate); exactly-once means exactly 1 (the hard one).
Producer side: acks=0 gives at-most-once (fire and forget); acks=1 or acks=all + retries gives at-least-once (retry may cause duplicates); enable.idempotence=true (with acks=all) ensures each (producerID, seqNumber) is written at most once per partition, eliminating duplicates from producer retries.
Consumer side: the key is when offsets are committed relative to processing. If you process first then commit, a crash between them causes reprocessing (at-least-once). If you commit first then process, a crash after commit but before finishing processing loses the message (at-most-once).
Exactly-once across producer + consumer: Kafka Transactions (since 0.11) let the producer atomically write to output topic and commit consumer offsets in the same transaction. Downstream consumers read with isolation.level=read_committed so they only see committed transactions.
Reality check: true end-to-end exactly-once requires either Kafka transactions with Streams API, or idempotent consumer logic (dedupe at sink using a unique message key). For most systems, at-least-once + idempotent consumer is the pragmatic choice.
Kafka supports three delivery semantics, but the guarantee depends on how both producer and consumer are configured. On the producer side: acks=0 means fire-and-forget — at-most-once because a network error silently drops the message. acks=1 waits for the leader to ack; acks=all waits for all in-sync replicas to ack. With acks=all and retries > 0, the default behavior is at-least-once because a network timeout can cause the producer to retry and the broker to write the same message twice. The fix is enable.idempotence=true — Kafka assigns each producer a unique producerID and a monotonically increasing sequence number per partition. The broker rejects duplicate (producerID, seq) pairs, so producer retries become idempotent automatically. With idempotence on, you get exactly-once per partition from the producer. On the consumer side, the knob is offset commit timing. Commit after processing → crash between processing and commit means reprocessing on restart → at-least-once. Commit before processing → crash after commit means lost message → at-most-once. End-to-end exactly-once across a consumer → producer pipeline needs Kafka Transactions, introduced in 0.11. The producer calls beginTransaction, writes output messages, sends commit offsets for input topics, then commitTransaction — all atomic. Downstream consumers set isolation.level=read_committed so they only see messages from committed transactions, never from aborted ones. Kafka Streams uses this under the hood for exactly-once processing. In practice, very few systems need true exactly-once; most pipelines are at-least-once with an idempotent sink — dedupe by message key in the database or downstream service. That pattern is simpler and handles more failure modes than trying to get true transactional exactly-once right.
Start by clarifying "exactly-once" is the end-to-end guarantee, not just the producer — candidates who conflate these lose points immediately.
Mention enable.idempotence=true and the (producerID, seq) mechanism — it separates textbook knowledge from hands-on experience.
Say honestly that "at-least-once + idempotent consumer" is what most production systems actually do.
If you blank on acks values or isolation.level during the interview, HireMe AI can surface the exact config strings.
No — idempotence prevents duplicates from producer retries only, and only within a single partition. End-to-end exactly-once needs consumer-producer transactions.
Throughput drops 10-30% and latency goes up because of the 2PC-style commit coordination with the transaction coordinator broker.
Not directly. Cross-cluster replication (MirrorMaker 2) is at-least-once. You need application-level dedup at the destination.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free