An idempotent producer is a client in a distributed messaging system that guarantees exactly-once delivery semantics by preventing duplicate writes during retries. It achieves this by assigning a unique producer identifier (PID) and a monotonically increasing sequence number to each message batch. The broker uses this tuple to detect and discard duplicates, ensuring that a retried send() operation does not result in multiple identical records in the log.
Glossary
Idempotent Producer

What is an Idempotent Producer?
An idempotent producer is a message producer configured to ensure that retrying a send operation does not result in duplicate records being written to the log, providing exactly-once semantics at the producer level.
This mechanism operates strictly at the producer-to-broker boundary and is a prerequisite for end-to-end exactly-once semantics when combined with transactional APIs. Idempotent producers eliminate the need for application-level deduplication logic for network-induced retries, but they do not protect against application-level logic that calls send() twice with the same data. The feature is enabled with a single configuration flag, such as enable.idempotence=true in Apache Kafka.
Key Features of an Idempotent Producer
An idempotent producer is a critical component in streaming data pipelines that guarantees no duplicate records are written to the log, even when network failures force the producer to retry a send operation. This provides exactly-once semantics at the producer level, a foundational requirement for accurate real-time personalization and inventory management.
In-Flight Request Ordering
To maintain the deterministic sequence number order, the idempotent producer restricts the maximum number of unacknowledged requests in flight per connection (max.in.flight.requests.per.connection) to 5 or fewer. This constraint is critical because it guarantees that the broker never sees a sequence number gap that could be misinterpreted as an out-of-order write, which would cause a fatal OutOfOrderSequenceException.
Session State and Zombie Fencing
The broker uses a combination of the PID and an epoch number to fence zombie producers. When a producer with the same transactional ID reconnects after a failure, the broker bumps its epoch. Any subsequent write attempt from the old producer instance with a stale epoch is immediately rejected with a ProducerFencedException. This mechanism prevents split-brain scenarios where a presumed-dead producer comes back and corrupts the log.
Performance Overhead
Enabling idempotence introduces a minimal, constant-factor overhead. The primary cost is the broker-side validation of sequence numbers and the maintenance of the PID cache. In practice, this overhead is negligible for most workloads, adding only microseconds of latency. However, it does require acks=all and a replication factor of at least 3 to ensure the PID state is durable, which increases write latency compared to acks=1.
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.
Frequently Asked Questions
Clear, technical answers to the most common questions about configuring and operating idempotent producers in distributed streaming systems.
An idempotent producer is a message producer configured to guarantee that retrying a send operation does not result in duplicate records being written to a distributed log, providing exactly-once semantics at the producer level. It works by assigning a unique Producer ID (PID) and a monotonically increasing sequence number to each message batch sent to a specific topic-partition. The broker tracks the last successfully committed sequence number for each PID-topic-partition tuple. If a retry causes a batch with a sequence number less than or equal to the last committed number to arrive, the broker silently discards it as a duplicate, acknowledging success to the client without rewriting the data. This mechanism eliminates the need for complex application-level deduplication logic caused by transient network failures or leader elections.
Related Terms
Understanding the idempotent producer requires familiarity with the surrounding messaging guarantees, failure modes, and architectural patterns that make exactly-once semantics possible in distributed streaming systems.
Exactly-Once Semantics
The delivery guarantee that an idempotent producer helps achieve. In distributed streaming, exactly-once semantics ensures that a message is both delivered and processed precisely one time, even when producers retry sends due to network failures or broker timeouts. This is distinct from at-least-once (which can produce duplicates) and at-most-once (which can lose messages). The idempotent producer addresses the producer-to-broker leg of this guarantee, preventing duplicate writes when acks=all acknowledgments are delayed but the original write actually succeeded.
Producer ID and Sequence Numbers
The internal mechanism that enables idempotency. When enable.idempotence=true is configured, the broker assigns a unique Producer ID (PID) during initialization. The producer then tags every message batch with the PID and a monotonically increasing sequence number. The broker tracks the last committed sequence number per PID-topic-partition combination. If a retry sends a batch with a sequence number less than or equal to the last committed value, the broker silently discards it as a duplicate, returning acknowledgment without rewriting the data.
Transactional Producer
An extension of the idempotent producer that adds atomicity across multiple partitions. While an idempotent producer prevents duplicates within a single partition, a transactional producer wraps writes to multiple partitions in an atomic unit using beginTransaction() and commitTransaction() calls. This guarantees that either all messages in a transaction are written and committed, or none are visible to consumers configured with isolation.level=read_committed. The transactional producer requires a unique transactional.id and builds on the same PID and epoch mechanisms.
Producer Retries and In-Flight Requests
The failure scenario that necessitates idempotency. When retries > 0 and max.in.flight.requests.per.connection > 1, a producer can send multiple batches without waiting for acknowledgment. If a network partition delays acknowledgment of batch N but batch N+1 succeeds, a retry of batch N would normally write a duplicate. The idempotent producer resolves this by enforcing ordering guarantees: with enable.idempotence=true, max.in.flight.requests.per.connection is capped at 5, and the broker uses sequence numbers to reject out-of-order duplicates.
Producer Epoch and Fencing
A mechanism to prevent zombie producers from corrupting the log. When a producer with a given transactional.id or PID reconnects after a session expiration, the broker increments its producer epoch. Any inflight or delayed requests bearing an older epoch are immediately rejected with a PRODUCER_FENCED error. This fencing token ensures that a producer instance that has been superseded cannot write stale data or commit a dangling transaction, protecting the integrity of the exactly-once guarantee across restarts and failovers.
Idempotency vs. Deduplication
A critical distinction in responsibility. The idempotent producer handles producer-level deduplication—preventing the same send operation from creating duplicate records in the log. This is distinct from consumer-side deduplication, where the consuming application must track processed message IDs to handle cases where the broker delivers the same message multiple times (e.g., after a consumer rebalance). True end-to-end exactly-once processing requires both: idempotent producers to prevent duplicate writes and idempotent consumers or transactional reads to handle duplicate deliveries.

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