How it works
The explanation, with examples you can run.
The ISR shrinks
On a three-broker KRaft cluster, a topic with three replicas and min.insync.replicas=2:
bin/kafka-topics.sh --bootstrap-server kafka1:9092 --create --topic ledger \ --replica-assignment 1:2:3 --config min.insync.replicas=2docker stop kafka3 # stop one brokerbin/kafka-topics.sh --bootstrap-server kafka1:9092 --describe --topic ledgerTopic: ledger Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 (before)Topic: ledger Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2 (after)Writes with acks=all still succeeded: two in-sync replicas meet the minimum.
Below the minimum
A second topic had two replicas (--replica-assignment 1:2) and min.insync.replicas=2. With broker 2 stopped, its ISR was just the leader, and an acks=all write failed:
Topic: ledger2 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1 Elr: 2WARN [Producer clientId=console-producer] Got error produce response with correlation id 7 on topic-partition ledger2-0, retrying (0 attempts left). Error: NOT_ENOUGH_REPLICASThe same write with acks=1 was accepted, and kafka-dump-log.sh showed it in the leader's log file. But a consumer read nothing and the latest offset stayed 0:
$ bin/kafka-get-offsets.sh --bootstrap-server kafka1:9092 --topic ledger2ledger2:0:0When broker 2 came back and rejoined the ISR, the latest offset became 2 and both records were readable. That is the documented behaviour: whatever acks the producer used, records are not visible to consumers until they reach all in-sync replicas and the ISR meets min.insync.replicas. In 4.x, with Eligible Leader Replicas (on by default for new clusters since 4.1), the high watermark cannot advance while the ISR is below the minimum, and replicas that left the ISR in that state (the Elr: 2 above) remain safe choices for leader.
Settings to decide on
default.replication.factor=3 # broker default is 1min.insync.replicas=2 # default is 1unclean.leader.election.enable=false- Replication factor 3, minimum 2,
acks=allis the usual production choice: it tolerates one broker failure without blocking writes or losing acknowledged data. - Minimum equal to the replication factor means any single broker failure blocks writes.
- Unclean leader election (off by default) lets a replica outside the ISR become leader when no in-sync one is left. The partition comes back sooner, without the records that replica never received.
Spread replicas across racks or availability zones with broker.rack, so one zone outage does not take every copy of a partition.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.