Q&A
Ask and answer questions to make information more available to wider audiences.
Felix Anguino @anguinofelix   13, Jul 2023 12:00 AM
Kafka producer maintain exactly once semantics
How can Kafka producer maintain exactly once semantics?
answers 1
 
Answer 1
Vanessa Lucas @lucasvanessa8   13, Jul 2023 05:24 PM
With Kafka messaging system, three different types of semantics can be achieved. 

At max once: Wherein a messaging system will never duplicate a message but might miss out on some messages occasionally.
At least once: Wherein a messaging system will never miss a message but might duplicate some messages occasionally.
Exactly once: Where in it will deliver all the messages without any duplication.

Kafka transactions help achieve exactly once semantic between Kafka brokers and clients. In order to achieve this we need to set below properties at producer end – enable.idempotence=true and transactional.id=<some unique id>. We also need to call initTransaction to prepare the producer to use transactions. With these properties set, if the producer (characterized by producer id> accidentally sends the same message to Kafka more than once, then Kafka broker detects and de-duplicates it.