Master Kafka’s Message Delivery Semantics: At-Most-Once, At-Least-Once, Exactly-Once
This article breaks down Kafka’s message delivery guarantees—at‑most‑once, at‑least‑once, and exactly‑once—explaining the underlying producer, broker, and consumer requirements, configuration settings, and practical code snippets to achieve reliable delivery.
Background
After reading the Kafka official documentation on message delivery semantics, the author found the material abstract and created a simplified summary with plain language examples and a concluding overview.
What levels of message delivery semantics exist?
Message delivery guarantees refer to how messages are transferred among the producer, broker, and consumer.
At-most-once – messages may be lost but are never duplicated. At-least-once – messages are never lost but may be duplicated. Exactly-once – each message is delivered one time and only once, which is the ideal guarantee.
Which delivery semantics does Kafka support?
The author summarizes the support based on the English documentation (see image below).
Does Kafka really support at-least-once delivery?
The answer depends on conditions; it may or may not be achieved.
Producer-side requirements for at-least-once
The producer retries sending messages when network issues occur, based on the retries setting, ensuring that a failed send is retried.
Prerequisites for the producer to achieve at-least-once:
The producer application must remain running (no restart or crash) during retries.
The network or broker must recover before the retry limit is exhausted.
Consumer-side approach
To guarantee at-least-once consumption, the consumer should manually commit offsets after processing each message. Example pseudocode:
while(true){
consumer.poll();
// process message
consumer.commit();
}Broker-side configuration
Ensuring the broker does not lose messages requires several settings:
Set producer acks to all.
Configure min.insync.replicas to at least 2.
Set replication.factor to at least 3.
Disable unclean leader election by setting unclean.leader.election.enable=false.
When the above conditions are not met, how to still achieve at-least-once
Adjust consumer and broker configurations as described, but the producer also needs persistent storage for outbound messages. If messages are persisted, a JVM restart, OOM, or crash will not cause loss, allowing at-least-once delivery once the system recovers.
For detailed explanations, see the referenced articles on Juejin.
Link: https://juejin.cn/post/7314870012975104009
(Copyright belongs to the original author, please delete if infringed.)
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
