What types of message delivery semantics does Kafka support?
Kafka supports three types of message delivery semantics:
- At most once: In this semantic, messages may be lost but will never be processed more than once. After the producer sends the message, there will be no confirmation or retry, which may result in message loss.
- At least once: In this context, messages will never be lost, but they may be processed multiple times. After a producer sends a message, the consumer can use an acknowledgment mechanism to ensure that the message has been processed correctly. However, if there are network failures or consumer failures that lead the producer to believe the message has not been processed, the message will be resent.
- Exactly once: This is the strictest message delivery semantics, ensuring that each message will only be processed once. Kafka achieves exactly once semantics through transactional and idempotent mechanisms to ensure that messages are not lost or processed multiple times during transmission between producers and consumers.
Due to the complex semantics and high performance cost of Exactly once, At least once is usually the most commonly used message delivery semantics. In Kafka, consumers can choose the appropriate message delivery semantics based on their needs to ensure the reliability and consistency of messages.