This topic is where durability is won or lost. The settings are small; the consequences are not.
acks: what "written" means
acks controls how many replicas must have the record before the leader acknowledges it.
| Value | Leader waits for | Durability | Failure mode |
|---|---|---|---|
0 | nothing | none | Record lost if the request never lands. The producer thinks it succeeded. |
1 | leader's own log | weak | Leader can acknowledge, then die before followers replicate. The record is gone and the producer was told it succeeded. |
all | all in-sync replicas | strong | Slower; can block writes when replicas fall behind |
The acks=1 window is the one people underestimate. It is not exotic — a broker restart during a deploy is enough.
acks=1 data loss
t0 producer → leader(b1): record at offset 500
t1 leader appends, replies "ok" ← producer moves on
t2 b1 crashes before b2/b3 replicate
t3 b2 elected leader, its log ends at offset 499
t4 offset 500 does not exist anywhere. No error was ever raised.
acks=all is only as strong as min.insync.replicas
acks=all means "all replicas currently in sync". If followers have fallen behind and been removed from the in-sync replica set, that could be one replica — the leader — and you are back to acks=1 durability without noticing.
The broker/topic setting min.insync.replicas closes this. With replication.factor=3 and min.insync.replicas=2, a produce request with acks=all fails (NotEnoughReplicasException) unless at least two replicas can accept it.
replication.factor = 3
min.insync.replicas = 2
ISR = {b1,b2,b3} → acks=all needs 3 → tolerates 1 slow/dead broker
ISR = {b1,b2} → acks=all needs 2 → still writable
ISR = {b1} → produce REJECTED → availability lost, durability kept
That last line is the real trade: you chose to stop accepting writes rather than accept writes you might lose. For anything financial or legally material, that is the correct choice. Setting min.insync.replicas equal to replication.factor leaves no tolerance for a single slow broker, so RF=3, min.insync=2 is the common sweet spot.
Retries create duplicates
Now the subtler failure. A produce request succeeds on the broker, but the acknowledgement is lost to a network timeout. The producer retries. The record is appended twice.
producer → broker: record A broker appends A at offset 100
broker → producer: ack ✗ lost in transit
producer times out, retries A broker appends A at offset 101
log: ... [100: A] [101: A] ...
Worse, with multiple in-flight requests per connection, a retried batch can be appended after a later batch, reordering records within a partition.
Idempotent producer
enable.idempotence=true fixes both. The producer gets a producer ID and stamps each batch with a monotonic sequence number per partition; the broker rejects a duplicate or out-of-order sequence for that producer.
This gives you exactly-once delivery into a partition for a single producer session, and it preserves ordering even with retries and multiple in-flight requests (up to 5). It requires acks=all, retries > 0, and max.in.flight.requests.per.connection <= 5; modern clients enable it by default and set those for you.
What it does not cover: a producer restart (new producer ID), or duplicates created by your own application logic retrying a business operation. For those you need transactions plus an idempotent consumer — covered in Module 3.
The delivery guarantee vocabulary
| Guarantee | How you get it on the produce side | Cost |
|---|---|---|
| At most once | acks=0 or acks=1 with retries disabled | Loses records |
| At least once | acks=all with retries | Duplicates possible |
| Effectively once | acks=all + idempotence (+ transactions for multi-partition atomicity) | Latency, complexity |
There is no single "exactly once" checkbox. Anyone who tells you otherwise has not read the retry path.
A sane durable baseline
acks=all
enable.idempotence=true
retries=MAX_VALUE
delivery.timeout.ms= bound total time you are willing to spend retrying
max.in.flight.requests.per.connection=5
topic: replication.factor=3, min.insync.replicas=2
retries=MAX_VALUE sounds reckless but is correct in modern clients, because delivery.timeout.ms is the real upper bound on how long a record may be retried before failing. Bound time, not attempts.
Exercise: A payments service runs acks=1, enable.idempotence=false, retries=3, on a topic with replication.factor=3 and min.insync.replicas=1. During a rolling broker restart, finance reports both a handful of missing payment events and a handful of duplicated ones. Explain which setting produced each class of error, and give the corrected configuration along with the availability trade-off it introduces.