What are Kafka’s message delivery semantics?
Three delivery semantics: At-most-once (may lose messages), At-least-once (may duplicate messages), Exactly-once (each message processed once, requires Kafka Streams or transactions).
How to achieve At-least-once delivery?
Producer: Set acks=all and retries>0. Consumer: Commit offsets only after processing messages. Risk: If consumer crashes after processing but before commit, messages are reprocessed.
How to achieve At-most-once delivery?
Producer: Set acks=0 or low retries. Consumer: Commit offsets before processing messages. Risk: If consumer crashes during processing, messages are lost.
How to achieve Exactly-once delivery?
Use Kafka’s idempotent producer (prevents duplicate sends) and transactional API with read_committed isolation level. Or use Kafka Streams with exactly-once processing guarantees.