Middle+
What do you know about delivery guarantees in Kafka?
sobes.tech AI
Answer from AI
Kafka has several levels of message delivery guarantees:
- At most once — a message may be lost but is not duplicated. Usually when the producer is disconnected before acknowledgment.
- At least once — a message is guaranteed to be delivered, but duplication may occur upon resend.
- Exactly once — a message is delivered and processed exactly once, without duplicates.
To ensure these guarantees, Kafka uses:
- acks — a producer parameter that determines how many replicas must confirm the write (0, 1, all).
- Message identifiers and offsets — for tracking read position.
- Transactions — to implement exactly-once semantics during message writing and processing.
Example of producer configuration for "at least once" delivery guarantee:
producer, _ := sarama.NewSyncProducer(brokers, &sarama.Config{
Producer: sarama.ProducerConfig{
RequiredAcks: sarama.WaitForAll, // wait for confirmation from all replicas
Retry: sarama.ProducerRetry{
Max: 5, // retry attempts
},
},
})
Thus, Kafka allows flexible configuration to balance between performance and delivery reliability.