Exactly-once semantics is a message delivery guarantee in distributed streaming systems ensuring that each record is processed precisely one time, eliminating both data loss and duplication. It is the strongest consistency guarantee, achieved through a combination of idempotent producers, transactional writes, and checkpointing in stream processors like Apache Flink or Kafka Streams.
Glossary
Exactly-Once Semantics

What is Exactly-Once Semantics?
A delivery guarantee in distributed systems ensuring that a message is processed only once, even in the face of failures, preventing data duplication or loss.
This guarantee is critical for stateful operations like financial transactions or inventory counts, where duplicates cause overcharging or stock discrepancies. It is implemented by atomically committing consumed offsets and output results to a state store, allowing the system to recover from failures by resuming from a consistent, non-duplicated checkpoint.
Key Characteristics of Exactly-Once Semantics
Exactly-once semantics (EOS) is a delivery guarantee ensuring that a message is processed only once, even in the face of failures, preventing data duplication or loss in distributed systems.
Idempotent Producers
The first pillar of EOS. An idempotent producer ensures that retrying a send operation does not result in duplicate records. The broker assigns a Producer ID (PID) and sequence number to each message. If a retry sends a message with a sequence number already committed, the broker discards it as a duplicate. This prevents the common 'at-least-once' duplication scenario where a producer retries after a network timeout without knowing the original write succeeded.
Transactional API
The second pillar enabling end-to-end EOS across multiple partitions and topics. The transactional API allows an application to group multiple produce and consume operations into an atomic unit. Key properties:
- Atomic multi-partition writes: Either all messages across partitions are committed, or none are visible.
- Read-Process-Write: Consume from a source topic, transform, and produce to a sink topic exactly once.
- Isolation: Consumers configured with
read_committedisolation level see only committed messages, filtering out aborted transactions and duplicates.
Two-Phase Commit Protocol
The underlying mechanism for distributed transactions in streaming systems. The process:
- Begin Transaction: Producer registers a new transactional session.
- Write Phase: Messages are written to partitions but marked as 'pending'—invisible to
read_committedconsumers. - Commit/Abort: The producer sends a commit marker to all involved partitions. This marker atomically flips pending messages to committed. If the producer crashes before committing, the transaction coordinator times out and aborts, preventing partial writes.
Failure Recovery & Zombie Fencing
EOS must handle producer failures gracefully. Zombie fencing prevents a crashed and restarted producer from corrupting state:
- Each new transactional producer session receives a monotonically increasing epoch number.
- If a zombie producer (with an older epoch) attempts to commit or send, the broker rejects the request with a
ProducerFencedException. - The transaction coordinator uses this epoch to guarantee that only the latest active instance can finalize a transaction, ensuring correctness during failover.
Performance Overhead Considerations
EOS is not free. The guarantees impose measurable overhead:
- Increased Latency: Transactional commits require additional round-trips to the transaction coordinator.
- Reduced Throughput: Up to 20-30% throughput reduction compared to at-least-once semantics due to coordination and marker writes.
- State Overhead: Brokers must maintain transaction state and pending markers in memory.
- Best Practice: Use EOS only for critical financial, billing, or inventory pipelines where duplication is unacceptable. For analytics pipelines tolerant of rare duplicates, at-least-once with idempotent consumers is often sufficient.
End-to-End Exactly-Once with External Systems
Achieving true end-to-end EOS requires coordination beyond the streaming platform. When the sink is an external database or service:
- Idempotent Writes: Design the sink to accept a unique key and perform an upsert, making duplicate writes harmless.
- Two-Phase Commit Integration: Use connectors that implement a two-phase commit protocol with the external system (e.g., Kafka Connect with JDBC sink).
- Outbox Pattern: Atomically write the event and update the business entity in the same local database transaction, then stream the event. This guarantees that the event is published if and only if the state change persists.
Delivery Semantics Comparison
A technical comparison of the three fundamental message delivery guarantees in distributed streaming systems, outlining their mechanisms, failure modes, and performance characteristics.
| Feature | At-Most-Once | At-Least-Once | Exactly-Once |
|---|---|---|---|
Core Guarantee | Messages are never duplicated but may be lost | Messages are never lost but may be duplicated | Messages are processed precisely one time with no loss or duplication |
Data Loss Risk | High | None | None |
Data Duplication Risk | None | High | None |
Producer Acknowledgment | Fire-and-forget; no ack required | Ack required; retry on timeout | Idempotent producer with transactional writes |
Consumer Offset Commit Strategy | Commit before processing | Commit after processing | Commit as part of atomic transaction with output |
Failure Recovery Mechanism | None; lost messages are not retried | Uncommitted messages are re-delivered after consumer restart | State snapshot and idempotent replay from last checkpoint |
Idempotency Required | |||
Transactional Support | |||
End-to-End Latency Overhead | Lowest | Moderate (retry overhead) | Highest (transaction coordination + deduplication) |
Throughput Impact | Highest throughput | Slightly reduced due to retries | 10-30% lower than at-least-once due to transactional overhead |
Out-of-Order Handling | Not applicable | May cause duplicate side effects | Idempotent writes tolerate reordering |
Use Case Suitability | Metrics, non-critical telemetry, best-effort logging | Most analytical pipelines, stateless ETL | Financial ledgers, inventory management, billing systems |
Example Technologies | UDP, basic Kafka producer (acks=0) | Default Kafka consumer, RabbitMQ with manual ack | Kafka transactions, Apache Flink with two-phase commit |
Frequently Asked Questions
A technical deep dive into the mechanisms and trade-offs behind ensuring each record in a distributed streaming pipeline is processed precisely one time, eliminating the risks of duplication or data loss.
Exactly-once semantics is a delivery guarantee in distributed streaming systems ensuring that a message is both delivered and processed only once, even in the face of network failures or system crashes. It works by combining idempotent producers, which prevent duplicate writes to a log, with transactional APIs that atomically commit consumed offsets and produced output. This mechanism prevents the two common failure modes: at-least-once (duplication) and at-most-once (data loss). In practice, systems like Apache Kafka and Apache Flink implement this using a two-phase commit protocol over a distributed log, where a transaction coordinator manages the atomicity of read-process-write cycles.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Understanding exactly-once semantics requires a firm grasp of the surrounding delivery guarantees, fault-tolerance mechanisms, and architectural patterns that make it possible in distributed streaming systems.
At-Least-Once Delivery
A weaker delivery guarantee where the system ensures no data loss but may introduce duplicates during retries. If a producer doesn't receive an acknowledgment due to a network timeout, it resends the message. The consumer must therefore be idempotent—able to handle and deduplicate repeat messages. This is the default guarantee in many systems like Apache Kafka without transactions, trading strict correctness for higher throughput and lower latency.
At-Most-Once Delivery
A fire-and-forget guarantee where messages are delivered zero or one time, with no retries on failure. If an acknowledgment is lost, the message is simply gone. This provides the lowest latency and highest throughput because the system never buffers or retransmits. It's suitable for non-critical telemetry, metrics, or sensor data where occasional loss is acceptable and freshness trumps completeness.
Idempotent Producer
A producer configured to ensure that retrying a send operation does not result in duplicate records in the log. In Apache Kafka, this is achieved by assigning each producer a unique ID and each message a sequence number. The broker tracks the last committed sequence per partition and rejects any retry with a lower or equal sequence, providing exactly-once semantics at the producer-to-broker boundary.
Transactional Messaging
A mechanism that allows a producer to atomically write to multiple partitions or topics and a consumer to atomically commit offsets back to the broker. In Apache Kafka, transactions span both input and output operations, enabling read-process-write patterns where consuming a message, transforming it, and producing a result are treated as a single atomic unit. This is the foundation for end-to-end exactly-once semantics.
Two-Phase Commit Protocol
A distributed algorithm that coordinates all participants in a transaction to either commit or abort atomically. In phase one, the coordinator asks all participants to prepare; in phase two, it tells them to commit or roll back. While foundational to transactional systems, it introduces blocking behavior if the coordinator fails. Modern streaming systems often optimize this with non-blocking variants or epoch-based commit protocols.
Idempotent Consumer
A consumer designed to produce the same result regardless of how many times it processes the same message. Strategies include:
- Deduplication by key: Storing processed message IDs in a state store and skipping repeats.
- Upsert operations: Writing results idempotently so reprocessing overwrites rather than duplicates.
- Deterministic logic: Ensuring business logic has no side effects that compound on replay. This is essential when exactly-once semantics cannot be guaranteed by the infrastructure alone.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us