Delivery Semantics: Exactly-Once vs At-Least-Once vs At-Most-Once
Fast recall
Quick revision
Core answer
Understanding of distributed messaging guarantees and the real cost of exactly-once semantics
Thinking exactly-once is free or easy — it requires idempotent producers, transactional consumers, and cross-system coordination
Explain idempotent producers in Kafka (enable.idempotence=true), transactional producers, and how consumer-side deduplication achieves effective exactly-once without full Kafka transactions
Interview-ready guide
Interview answer
These three delivery semantics describe what happens when failures occur in the messaging pipeline.
- At-most-once acknowledges before processing — fast, but if the consumer crashes, the message is gone.
- At-least-once acknowledges after processing — no message loss, but the producer might retry or the consumer might reprocess after a crash, creating duplicates.
Exactly-once — the expensive guarantee:
- Requires coordination between producer, broker, and consumer that adds roughly 2–3× latency per batch
- Kafka achieves it with idempotent producers — which deduplicate retries using a sequence number, enabled by default since Kafka 3.0 — plus transactional producers that atomically commit consumed offsets and produced messages
- The important boundary: Kafka's exactly-once guarantee stops at Kafka; writing to PostgreSQL or calling a payment API is outside the transaction, so external effects still need application-level idempotency
The practical alternative — at-least-once with idempotent consumers:
- Most systems don't need true exactly-once; at-least-once with idempotent consumers gives effectively the same outcome at lower cost
- If your consumer checks a processed-events table before doing work, or uses database upserts, or relies on naturally idempotent operations like setting a status field, then duplicates are harmless
- You end up writing deduplication logic anyway even with Kafka transactions, since external effects are outside the transaction boundary
When to use each:
- At-least-once with idempotent consumers for the vast majority of event processing
- Reserve Kafka transactions for financial ledgers and billing where a duplicate line item is a compliance violation
I recommend at-least-once with idempotent consumers as the default — it gives you safety without the Kafka transaction latency overhead, and you control the deduplication logic explicitly.
Delivery Semantics: Exactly-Once vs At-Least-Once vs At-Most-Once
Direct Answer
at-most-once: may lose messages, never duplicates (fire-and-forget). at-least-once: no message loss, may duplicate (most systems default). exactly-once: no loss, no duplicates — achievable in Kafka via idempotent producers + transactional consumers, but adds latency and complexity. Most production systems use at-least-once with idempotent consumers.
Common Mistakes & Pitfalls
Thinking exactly-once is free or easy — it requires idempotent producers, transactional consumers, and cross-system coordination
Check your understanding
Answer these without looking back at the article.
- How does Kafka's idempotent producer differ from transactional producers?
- What is the read_committed isolation level in Kafka consumers?
- How would you implement idempotency in a consumer that writes to PostgreSQL?
Related interview prep categories
2Want a guided curriculum order?
These modules are also sequenced in our flagship backend interview track — open it when you prefer an ordered path instead of browsing by topic.