Sobes.tech
Senior

If we talk about Kafka, what delivery guarantee do you support?

sobes.tech AI

Answer from AI

In Kafka, three main levels of message delivery guarantees can be ensured:

  1. At most once — a message may be delivered 0 or 1 times. Message loss is possible, for example, if a failure occurs before acknowledgment.

  2. At least once — a message will be delivered guaranteed, but may be delivered multiple times (duplicates). This is achieved through acknowledgments from the broker and retransmission if necessary.

  3. Exactly once — the strictest guarantee, where a message is delivered and processed exactly once. In Kafka, this is achieved using idempotent producers and transactions.

In Go, when working with Kafka (for example, using the sarama library), you can configure the producer for idempotent sending and use transactions to ensure "exactly once". By default, "at least once" is most commonly used.

Example of configuring an idempotent producer in Go with sarama:

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

producer, err := sarama.NewSyncProducer(brokers, config)
if err != nil {
    panic(err)
}
// Then send messages through the producer
If we talk about Kafka, what delivery guarantee do… - sobes.tech