Sobes.tech
Senior

What guarantees of delivery have you encountered in Kafka, what are they, and which ones have you worked with?

sobes.tech AI

Answer from AI

Apache Kafka has three main message delivery guarantees:

  1. At most once — a message may be delivered 0 or 1 times. Loss of messages is possible, but duplicates will not occur.

  2. At least once — a message is guaranteed to be delivered, but may be delivered multiple times (duplicates possible).

  3. Exactly once — a message is delivered exactly once, with no losses or duplicates. This is the most complex guarantee, implemented using idempotent producers and transactions.

Which ones I have encountered:

  • Usually, the at least once guarantee is used, where the producer confirms the record, and the consumer processes it while maintaining offsets after successful processing.
  • For critical systems, the exactly once mode with transactions was used to avoid duplicates in case of failures.

Example of configuring a producer for idempotency in Go (using the sarama library):

config := sarama.NewConfig()
config.Producer.Idempotent = true
config.Producer.RequiredAcks = sarama.WaitForAll
config.Producer.Retry.Max = 5

producer, err := sarama.NewSyncProducer(brokers, config)

Thus, the choice of guarantee depends on the system's reliability and performance requirements.

What guarantees of delivery have you encountered in… - sobes.tech