📨 Apache Kafka Intermediate

What are Kafka delivery semantics?

Answer

Kafka supports three delivery guarantees. At-most-once: messages may be lost but never duplicated. Use acks=0 or acks=1 without retries. Consumer commits offsets before processing — if processing fails, the message is lost. Acceptable for metrics/logging where loss is tolerable. At-least-once: messages are never lost but may be duplicated. Use acks=all with retries. Consumer commits offsets after processing — if crash before commit, the message is reprocessed. Requires idempotent consumers. Default production pattern. Exactly-once: no loss, no duplication. Use Kafka's idempotent producer (enable.idempotence=true) and transactions for atomic read-process-write. Required for financial transactions. Kafka Streams implements exactly-once semantics with processing.guarantee=exactly_once_v2. Exactly-once has performance overhead but is necessary for correctness in some scenarios.