Key takeaways
- ✓The acks setting decides when a Kafka producer hears "done": with acks=1 the leader's own write is enough, and with acks=all the leader waits until every in-sync replica (ISR, the copies that have kept up recently) has the message.
- ✓With both followers frozen 2 seconds before the leader was killed, acks=1 lost 104,019 of 1,249,984 confirmed messages (8.3%) over 5 runs, between 20,615 and 21,034 a run, and the producer was told of zero failures.
- ✓With the followers keeping up, acks=1 lost 54 confirmed messages in 1 of 20 runs, a window of about 5 ms before the kill, so the flaw shows up rarely and nothing reports it.
- ✓acks=all lost 0 of 4,999,684 confirmed messages in 20 healthy runs and 0 of 1,249,987 in 5 frozen runs, but it confirmed nothing while the followers were frozen, so its write stall began 2.0 seconds before the kill.
- ✓Under either setting, each failover stopped writes for 9.1 to 15.2 seconds, because the cluster waits 9 seconds (broker.session.timeout.ms) before it moves leadership, so acks=all buys durability, not availability.
- ✓Kafka's throughput rose 2.9 times from 1 to 12 partitions and 3.2 times from no batching to a 50 ms wait with 1 MB batches, and at full speed it ran 5.9 to 7.2 times the throughput of a one-node RabbitMQ quorum queue.
The producer was told "done" 104,019 times for messages that were then gone. The setup was one partition with three copies, a write rate of 10,000 messages a second, and the partition's leader killed on purpose. Under the cheaper setting, acks=1, with both followers paused for the 2 seconds before the kill, the new leader lacked those 2 seconds of messages, and when the old leader returned they were removed from the partition. Under acks=all, the same test lost none. This chapter explains what each setting promises, what the lab measured, and what it did not test.
The examples come from Lab 12 (Queues and Event Streams (Kafka)) of the system design labs, script 06_broker_kill.py for the kills and 07_throughput.py for the speed figures. The lab ran on an Apple M4 Max with Docker Desktop and 16 virtual CPUs, with Kafka 4.1.1 on three brokers (the servers that store the topic, the named stream of messages). The laptop was busy during the throughput runs, so read ratios within a table rather than absolute rates across tables. The two settings alternated run by run, and all 50 runs are recorded in data/results/06_broker_kill.json.
What "confirmed" means to a producer
A producer sends a message and waits for a reply. The reply is an ack (short for acknowledgement), and it is the producer's receipt. Once it has the receipt, the producer treats the message as safe and moves on. Nothing in the producer's code can check what the receipt really covered. It covered exactly what the acks setting promised, and that is all.
Think of a counter with three clerks. The leader is the clerk at the counter, and two followers copy each entry into their own notebooks. The receipt can be handed over as soon as the leader writes the entry, or only after both followers have copied it too. The first kind of receipt is cheaper and faster, and the second kind survives the leader walking out the door.
What each setting promises
acks=0: the producer does not wait for any reply at all. It promises nothing about the write, so a message can disappear without the producer ever knowing. The lab did not run this setting, so the claim here is about Kafka's documented behaviour, not a measurement.acks=1: the leader confirms as soon as it has written the message. The followers may not have it yet. If the leader dies in that window, the message can be lost while the producer holds a receipt for it.acks=all: the leader confirms only when every in-sync replica has the message. The in-sync replicas (ISR) are the copies that have kept up recently, withinreplica.lag.time.max.ms, which defaults to 30 seconds. A confirmed message is on every copy that is still in the ISR.
A second setting, min.insync.replicas=2, sets how many copies must be in the ISR before a write with acks=all is accepted at all. Here it means at least two copies, the leader included, must be in sync, so one crash cannot leave the only copy. The lab set it on the topic and kept unclean.leader.election.enable off, so a replica outside the ISR could not take over.
Why a lagging follower matters
A follower that is 2 seconds behind is still in the ISR. Being in sync means it has caught up within the last 30 seconds, not that it has every message right now. So the leader confirms messages under acks=1 while that follower is still counted as a healthy copy.
When the leader is killed, the cluster elects a new leader from the ISR, and the 2-second-behind follower can be the one chosen. The messages from those 2 seconds, which only the old leader had, do not exist on the new leader. When the old leader restarts, it has to match the new leader's log, and those messages are gone. Kafka's design does this truncation. The lab measured its result, the missing messages, not the truncation step itself.
The workflow
06_broker_kill.py runs the same steps for each condition.
- Create a topic with one partition, a replication factor (RF) of 3,
min.insync.replicas=2, and unclean leader election off. - Look up the partition's leader and its two followers.
- Start a producer at 10,000 messages a second for 25 seconds, with
acks=1oracks=all. Each message carries a sequence number, and the producer records which ones were confirmed. - In the frozen runs, pause both followers with
docker pausefor the 2 seconds before the kill. This stands in for a long garbage-collection pause or a network blip, when both copying clerks look away. - At 7 seconds, kill the leader with SIGKILL, which gives it no chance to clean up. Restart it 15 seconds later. The 15 seconds matter: the cluster waits 9 seconds before it notices a dead broker, so a shorter outage would just resume the old leader and measure nothing.
- Wait until the ISR is back to 3, read the whole partition, and compare it with the confirmed sequence numbers. A confirmed message that is not in the partition counts as lost.
The lab ran 20 runs per setting with healthy followers, alternating acks=1 and acks=all, and 5 runs per setting with the followers frozen. That is 50 runs in all.
What the runs showed
| Followers | Producer setting | Runs that lost a confirmed message (95% range) | Confirmed, then lost | Lost per run (min to max) | Producer told of a failure | Write stall, median |
|---|---|---|---|---|---|---|
| Keeping up | acks=1 |
1 of 20 (1–24%) | 54 of 4,999,918 | 0 to 54 | 0 | 10.1 s |
| Keeping up | acks=all |
0 of 20 (0–16%) | 0 of 4,999,684 | 0 | 0 | 11.1 s |
| 2 s behind | acks=1 |
5 of 5 (57–100%) | 104,019 of 1,249,984 (8.3%) | 20,615 to 21,034 | 0 | 13.0 s |
| 2 s behind | acks=all |
0 of 5 (0–43%) | 0 of 1,249,987 | 0 | 0 | 15.1 s |
Three readings from the table.
- The lag turns a rare loss into a certain one. With healthy followers, the leader's head start was a few milliseconds, and the kill landed in that window in one run out of 20. With followers 2 seconds behind, the window was 2 seconds of writes, about 20,800 messages in a typical run (the median was 20,769), and every frozen
acks=1run lost them. - The producer could not tell the settings apart. Across all 50 runs it saw no failed send and no duplicate. Its view of
acks=1andacks=allwas identical, so the loss shows up only when someone checks the partition. acks=allpaid in time, not in data. It confirmed nothing during the freeze, so its write stall began when the followers froze, 2.0 seconds before the kill. Its stall ran about 15 seconds against 13 foracks=1.
Both followers paused (docker pause) for the 2 s before the kill, so they lack the last 2 s of writes. 5 runs per setting.
acks=1
the leader's write is enough to confirm
5 of 5 runs lost a confirmed message (100% of runs; 95% range 57–100%)
acks=all
every in-sync copy must have it first
0 of 5 runs lost a confirmed message (0% of runs; 95% range 0–43%)
The producer saw no error and no duplicate in any of the 50 runs, under either setting. The lost messages were confirmed, so the only place to find them is the partition after the restart.
The failover gap
Every failover stopped writes for a while, under both settings. The stalls ranged from 9.1 to 15.2 seconds, and their medians were 10.1 and 11.1 seconds with healthy followers, 13.0 and 15.1 with frozen ones. The gap has two parts. First, about 9 seconds (broker.session.timeout.ms) pass before the cluster decides a silent broker is dead and moves leadership. Then up to about 5 more seconds pass, in steps of roughly one second, while a new leader is chosen and the producer finds it. The lab's test did not measure those two parts separately.
So acks=all is not an availability feature. It keeps the confirmed messages, and it stops writes just as long as acks=1 does when a leader dies.
How fast is it?
Waiting for every copy costs time, so the lab also measured Kafka's own load tool with acks=all, a kilobyte per message, and three copies.
- Partitions: one partition gave 84,938 messages a second, and 12 partitions gave 242,522, which is 2.9 times as many. Each partition has its own leader, spread over the brokers, so writes run side by side.
- Batching: a batch is many messages sent in one request. Sending with no wait, in 16 KB batches, gave 115,473 a second. Waiting up to 50 ms, for 1 MB batches, gave 367,197, which is 3.2 times as many.
- RabbitMQ: at full speed, Kafka took 291,121 and 297,472 messages a second against 40,440 and 50,225 for a one-node RabbitMQ quorum queue (a replicated queue type). That is 5.9 to 7.2 times as many. The comparison is not like-for-like, because Kafka ran six partitions against the queue's one.
- At everyday rates: at 5,000 and 20,000 messages a second, the median confirm took 3 to 8 ms for Kafka and 1 to 3 ms for the quorum queue, and 0.5 to 0.6 ms for RabbitMQ's classic queue. At those rates, the choice rests on features more than speed.
Caveats
- One partition per test. Real topics have many partitions, and a broker usually holds only some of them.
- The frozen runs are 5 each. The 95% range for
acks=allwith frozen followers is 0 to 43%, so zero lost in 5 runs does not rule out a rare loss. The 25acks=allruns together bound the rate at about 13%, and the 20 healthy runs alone at about 16%. - The settings differ in more than acks. The lab's producer turns on idempotence (a setting that stops a retried send from being written twice) only for
acks=all, because Kafka requires acks=all for it. The comparison is therefore between the two producer configurations, not betweenacksalone. - The freeze is
docker pause, not a real garbage-collection pause. Both followers were frozen for 2 seconds, which is about the lag that matters. A longer freeze, or a freeze of one follower only, was not tested. - The 30-second ISR window is a default. The lab's script comment gives the
replica.lag.time.max.msdefault, and the lab did not change it or test it. - No power loss. The copies were killed as processes. The lab did not test all three machines losing power before the page cache was flushed to disk, which is a separate risk.
- acks=0 was not run, and neither was a leader crash with
unclean.leader.election.enableon. Under that setting, a replica outside the ISR can become leader, so it can lose data even withacks=all. - The throughput figures are from a busy laptop. The load average recorded with the throughput run was about 119. Trust the three-fold gaps, and treat smaller differences as noise.
The checklist
- Know what your producer's receipt means. Check
acksin the producer's configuration.acks=1means one copy, andacks=allmeans every in-sync copy. - Pair
acks=allwithmin.insync.replicas=2on any topic whose messages you cannot lose, and keep unclean leader election off. - Treat a lagging follower as a risk, not a healthy copy. A follower can be in the ISR for up to 30 seconds while missing the last 2 seconds of writes.
- Plan for the failover gap. Under either setting, expect writes to stop for 9 to 15 seconds when a leader dies.
- Check the data, not the producer's errors. The producer reported zero failures in all 50 runs, so only a count of confirmed messages against the partition shows the loss.
Quiz
1.A producer with acks=1 gets a confirmation, and then the leader dies before any follower has copied the message. What happens to that message?
2.With both followers frozen for 2 seconds, acks=all lost no confirmed messages in 5 runs. Why?
3.With the followers keeping up, acks=1 lost 54 confirmed messages in one run out of 20. What was the window?
Check your understanding
Try each question before opening its answer.
The producer saw no error in the 5 frozen acks=1 runs, yet 104,019 confirmed messages were gone. Why could it not tell?
The receipt it got covered only what acks=1 promises: the leader had written the message. The producer has no way to see whether the followers had copied it, and the new leader's loss shows up later, in the partition, after the old leader restarts. That is why the lab counted the partition's contents against the confirmed sequence numbers, and why its producer view was identical under both settings.
Frozen followers stayed in the ISR. Why does that matter for acks=all, and why does it not save acks=1?
Because the frozen followers were still in the ISR, acks=all kept waiting for them, so it confirmed nothing during the freeze and its write stall began 2.0 seconds before the kill. acks=1 never waited for them, so it kept confirming, and the 2 seconds of messages only the leader had were the ones lost when a frozen follower became leader.
Acks=all lost nothing in 25 runs, and its stall was 11 to 15 seconds. Did it avoid the failover gap?
No. Both settings stalled for 9.1 to 15.2 seconds per failover, because the cluster waits about 9 seconds (broker.session.timeout.ms) before it moves leadership. acks=all kept the confirmed messages; it did not keep writes flowing during the change of leader.
Why did the lab set unclean leader election off, and what would turning it on change?
With unclean leader election on, a replica that is outside the ISR can become leader when no in-sync replica is left, and it can be behind the old leader. That can lose data even with acks=all, because the new leader is missing confirmed messages. The lab kept it off in every run, so it did not test this case, and its results apply only to the in-sync election path.
Next up: Chapter 29, two-phase commit: one action across several services, when a single transaction can't cover them all.