When a Kafka OK means your message is saved
With acks=1 a leader crash can lose messages Kafka confirmed; acks=all plus min.insync.replicas=2 stops that.
Published here , tested on Apache Kafka 4.1.0 (1 KRaft controller + 3 brokers) in Docker 29.4.0 on macOS 27.2 · 4 sources · Resume reading
Kafka can lose a message it already said OK to. It happens with the producer setting acks=1 when the leader dies before its followers copy the message [1]. This page is part 2 of what happens when you send a message to Kafka, and it uses the numbers from the run shown in the video: Apache Kafka 4.1.0 in Docker, three brokers and one KRaft controller on one machine, recorded on 2026-11-16.
Kill the leader and watch who takes over
In part 1, the order sat at offset 1447 in partition 1, on broker 2 (the leader), with copies on brokers 3 and 1. In the run, broker 2 was killed with no clean shutdown.
A controller tracks every broker through heartbeats. A broker's lease lasts broker.session.timeout.ms without heartbeats, 9 seconds by default [2]. The new leader can only come from the in-sync replicas [3], and unclean.leader.election.enable is false by default [2]. In the run, broker 3 led partition 1 after 9.7 seconds, with in-sync replicas 3 and 1.
The order was still at offset 1447. The next order from the same user went in at 1448, on the new leader.
Know what in-sync means
A follower leaves the in-sync set if it has not fetched, or not caught up to the leader's log end, for replica.lag.time.max.ms, 30 seconds by default [2]. So a follower a few seconds behind still counts as in sync, and it can be missing the newest messages.
Set acks on the producer
acks decides when the producer hears OK. With acks=1, the leader writes the record to its own log and answers without waiting for the followers. Per the docs, if the leader fails right after that answer and before the followers have the record, the record is lost [1]. With acks=all, the leader waits for the full set of in-sync replicas [1]. The default is all [1].
acks=allCompare the two settings under the same crash
The run tested both settings on a one-partition topic with three replicas. Both followers were frozen, the producer kept sending, and then the leader was killed.
With acks=1, five messages got an OK. A follower took over without them, because it was still in sync, and new messages were written into the same offsets. Those five were gone from the log.
With acks=all and min.insync.replicas=2, the five messages in flight got an error instead of an OK. Zero confirmed messages were lost. A default Java producer retries such errors: retries defaults to 2147483647, bounded by delivery.timeout.ms, 120000 ms by default [1]. The test tool in the run reported the errors and did not retry.
Set min.insync.replicas to 2 on the topic
min.insync.replicas is the minimum number of in-sync replicas, the leader included, that must have a write for it to succeed. Its default is 1 [2]. If both followers drop out of the in-sync set, acks=all with the default would wait for the leader alone. With 2, Kafka refuses the write. The topic config command follows the operations docs [4].
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --alter --add-config min.insync.replicas=2bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --describeYou should see min.insync.replicas=2 in the topic's config list.
Accept the throughput cost
Waiting for copies costs speed. On the run's one machine (200-byte messages, three partitions, replication factor 3, min.insync.replicas=2), acks=all sent 229,043 messages a second and acks=1 sent 564,334. All brokers shared that one machine, so treat these as a ratio for that setup only.
An OK means saved when the topic has three replicas, the producer uses acks=all, and min.insync.replicas is 2.
Send this to the teammate whose Kafka producer still uses acks=1 for orders.
Keep this guide
Filed under Dev explainers
Questions about this guide
Can Kafka lose a message it already acknowledged?
Yes, with `acks=1`. Per the producer docs, if the leader fails right after acknowledging a record and before the followers have copied it, the record is lost.
What is the default for acks?
`all`, per the Kafka 4.1 producer configs. The leader then waits for the full set of in-sync replicas before it says OK.
Why set min.insync.replicas to 2?
Followers that fall more than `replica.lag.time.max.ms` (default 30 seconds) behind leave the in-sync set. With the default `min.insync.replicas` of 1, `acks=all` could then be satisfied by the leader alone. With 2, Kafka refuses the write instead.
How long does a leader failover take?
A broker's lease lasts `broker.session.timeout.ms`, 9 seconds by default, if it stops sending heartbeats. In the run shown in the video, the new leader took over after 9.7 seconds.
Sources
- Apache Kafka 4.1 docs: Design (Replication)kafka.apache.org
- Apache Kafka 4.1 docs: Basic Kafka operations (topic configs)kafka.apache.org