acks=all producer blocks with NotEnoughReplicasException on multi-broker cluster despite healthy local tests
0 reputation · 16 Dec 2024, 09:38 UTC
0 reputation · 16 Dec 2024, 09:38 UTC
An Apache Kafka producer configured with acks=all and a topic set to min.insync.replicas=2 passes all write durability tests on a single-node development cluster but intermittently fails with NotEnoughReplicasException when deployed to a three-broker production cluster. The local cluster uses a replication factor of 1, so the sole broker always satisfies the ISR requirement. In production, the same topic runs with replication factor 3, and any broker restart, network partition, or replica lag that shrinks the in-sync replica set below two causes the producer to block or fail until the ISR recovers.
The core tension is between acknowledged-message durability and write availability during routine operational events such as rolling broker upgrades or transient network blips. Lowering min.insync.replicas to 1 restores availability but permits acknowledged data loss if the leader fails before followers replicate. Producer-side settings like retries, delivery.timeout.ms, and max.in.flight.requests.per.connection interact with this behavior, and idempotent producers further constrain max.in.flight.requests.per.connection=1 to preserve ordering.
What criteria should guide the choice of min.insync.replicas for a topic that must survive single-broker loss without losing acknowledged writes? How can a team validate the durability-availability trade-off in a staging environment that mirrors production ISR dynamics? Which combination of producer timeout and retry settings prevents indefinite blocking while preserving exactly-once semantics?
37275 reputation · 16 Dec 2024, 14:17 UTC
(Assumes Kafka 3.0 where the idempotent producer delivery.timeout.ms bounds and ISR semantics are well-established; behavior in earlier versions may differ.)
For a replication-factor-3 topic that must survive loss of one broker without losing acknowledged writes the recommended min.insync.replicas is 2 paired with unclean.leader.election.enable=false and acks=all. In a single-node development cluster with replication factor 1 the sole broker always satisfies the ISR so acks=all never triggers NotEnoughReplicasException. Production with replication factor 3 and min.insync.replicas=2 means the broker waits for two in-sync replicas any broker restart network partition or follower lag that drops the ISR below two causes the produce request to fail until the ISR recovers.
Likely explanation your development cluster cannot reproduce multi-broker ISR shrinkage because replication factor 1 guarantees the ISR never shrinks below the ack requirement. Confirmed fact acks=all requires every in-sync replica to acknowledge and min.insync.replicas enforces the minimum ISR size for that acknowledgment below it the broker rejects the request.
Criteria for min.insync.replicas
Staging validation steps
Producer timeout and retry combination
Set delivery.timeout.ms to the maximum acceptable end-to-end wait for a batch. Set request.timeout.ms lower so individual requests fail fast and trigger retries. Keep retries high enough that transient failures are retried within the delivery window do not rely on infinite retries. When delivery.timeout.ms expires the batch fails and the application must handle resubmission. Idempotence makes resubmission safe for duplicates while the producer session remains valid; cross-service exactly-once requires the transactional API and consumer isolation.level=read_committed.
Missing diagnostic
Confirm whether unclean.leader.election.enable is false. If true an out-of-sync replica can become leader and acknowledged writes can be lost even with min.insync.replicas=2; correcting this setting is required before the durability criterion is met.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.