Idempotent Producer: Limits on In‑Flight Requests and Retry Behavior
0 reputation · 30 Sept 2026, 12:25 UTC
0 reputation · 30 Sept 2026, 12:25 UTC
The Kafka idempotent producer, introduced in 0.11, guarantees that a message with a given producer ID and sequence number is written at most once to a partition. To preserve ordering, the feature requires that max.in.flight.requests.per.connection be set to 5 or less.
When a producer retries after a network failure, the broker may have already persisted a partially written record. Because the idempotent guarantee is per producer instance, a reconnect could lead to a duplicate if the broker does not roll back the partial write. This scenario is not yet fully documented.
During a rebalance, an idempotent producer may abort pending transactions. If the abort does not occur before the next send, transient duplicates can appear, potentially violating exactly‑once semantics.
32775 reputation · 30 Sept 2026, 22:12 UTC
For an idempotent Kafka producer the setting max.in.flight.requests.per.connection must be ≤ 5; otherwise ordering guarantees are lost and, in Kafka 3.0+, the broker rejects the configuration with an error.
transactional.id is set), the broker increments the producer epoch during a rebalance, causing any in‑flight request from the old epoch to be rejected with INVALID_PRODUCER_EPOCH.enable.idempotence=true (KIP‑360) and strengthens epoch fencing and producer state snapshots (KIP‑447).The worry that a broker could retain a partially written record and later cause a duplicate after a producer reconnect stems from a misunderstanding of the log append semantics. Because the broker only commits whole batches, any incomplete data is removed on restart, and the idempotency check uses the producer’s sequence number, so a retry with the same sequence is treated as a duplicate and discarded.
enable.idempotence=true, max.in.flight.requests.per.connection ≤ 5, and appropriate acks (≥ 1) and retries > 0.transactional.id, verify that transactional.id.expiration.ms is set as desired and that the producer handles INVALID_PRODUCER_EPOCH gracefully.Are you using a transactional ID (i.e., transactional.id set) or relying solely on enable.idempotence=true? The answer changes whether rebalance‑induced epoch fencing applies and whether you need to handle INVALID_PRODUCER_EPOCH.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.