Kafka · mid
Kafka producers: acks, replicas and the idempotent producer
A send that reports success is not always safe. Durability depends on acks, the in-sync replicas and min.insync.replicas. The idempotent producer stops duplicates from retries, but only inside one producer session.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- acks=all waits for the replicas that are currently in the in-sync replica set (ISR), not for every replica. With min.insync.replicas=1, a leader whose followers have dropped out of the ISR accepts writes alone.
- acks=1 means only the leader has the record when the send succeeds. If the leader dies before followers copy it, the record is gone.
- Safe setup: replication factor 3, min.insync.replicas=2, acks=all, unclean.leader.election.enable=false, replicas spread across zones (broker.rack).
- Unclean leader election lets an out-of-date replica become leader. The writes it never copied are lost. Its default is false.
- The cost of safety: if two of three replicas are down, producers get NotEnoughReplicas errors. This is durability over availability, so producers need retries and an outbox.
- In current Kafka clients the defaults are acks=all, enable.idempotence=true and delivery.timeout.ms of 2 minutes. Do not override them with weaker values.
- Idempotent producer: the broker gives a producer id and every batch carries a sequence number per partition. The leader drops a batch it already wrote, so a retry after a lost acknowledgement does not write twice, and order holds with up to 5 requests in flight.
- Not covered: your code calling send() twice, a restarted producer (a new producer id), duplicates across partitions, and everything on the consumer side. Transactions with a transactional.id and read_committed readers cover read-process-write inside Kafka only.
The red pen
Common traps: mistake → fix
Mistake: acks=all means every replica has the record
Fix: only the current in-sync replicas.
Mistake: The idempotent producer means exactly-once end to end
Fix: it covers only retries in one producer session.
Mistake: The send succeeded in the log, so the event is safe
Fix: check acks, min.insync.replicas and callbacks.
Mistake: Replication factor 2 with min.insync.replicas=2 is safe
Fix: one broker down stops all writes.
Easy to hard
Questions interviewers ask, easy to hard
- What does acks=all really guarantee?
- What does the idempotent producer protect against, and what not?
- 3,000 payment events were lost after one broker died. How do you investigate?
- What settings do you recommend for a payments topic?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.