Lesson 4 · Reliability core
Producers, keys & acks
How a write becomes durable — and the knob that decides how durable.
Your win: explain what happens when a producer sends an event,
what acks = 0 / 1 / all really trade off, and why our producer chose
RequireOne — including the risk that choice accepts.
A produce is a write to the partition leader
When a producer sends an event, three things happen in order: the partitioner uses the key to pick a partition (Lesson 2), the producer sends the batch to the broker that holds that partition's leader replica, and the leader appends it to the log.1 Producers batch and retry automatically — they're built to be reliable and fast.
Our wrapper's writer shows both the partitioner and the retry policy in one place:
internal/golibs/kafka/kafka.go:465writer := &kafka.Writer{
Balancer: &kafka.Hash{}, // key → partition (Lesson 2)
MaxAttempts: math.MaxInt32, // retry sends ~forever
RequiredAcks: int(kafka.RequireOne), // the durability knob ↓
}
acks: how many replicas must confirm
acks (in segmentio, RequiredAcks) is the durability
setting. It says how many replicas must acknowledge the write before the producer
treats it as done.2
acks | Waits for | If the leader dies… | Feel |
|---|---|---|---|
0 | nothing (fire-and-forget) | silently lost | fastest, least safe |
1 / RequireOne | leader only | lost if it hadn't replicated yet | our setting — middle ground |
all / RequireAll | the full in-sync replica set | safe — a follower has it | slowest, strongest |
acks buys durability with latency. 0 can lose data,
all guarantees a replica has it before you move on, 1 sits
between — safe unless the leader dies in the brief window before a follower copied
the write.
Why RequireOne for us — and the risk it accepts
Our producer uses acks=1: wait for the leader, not the whole replica
set. That keeps produce latency low (the API returns fast — remember Lesson 1), at
the cost of a narrow data-loss window if a leader crashes before its followers catch
up. For emails and notifications that's an accepted trade: throughput matters, and
the consumer side is designed to tolerate the occasional lost or duplicated event
(Lessons 5–6). An interviewer loves this answer because it's a choice with a
reason, not a default.
acks is a producer setting about durability of a
write. It is not the same as a consumer committing an offset
(Lesson 5). Mixing these up is the most common Kafka interview stumble. Producers
ack; consumers commit.
The key is a first-class reliability tool
You met the key in Lesson 2 as "chooses the partition." Reframe it now as a
reliability lever: by keying on EmailID, we guarantee all events for one
email are ordered and land on one leader — so ordering survives even under
producer retries. Choosing a good key is a design decision, not an afterthought.
Apache Kafka 101 — Producers
Short, concrete, from Confluent. Then read the Kafka docs' producer/durability
notes for the precise acks definition.
→ developer.confluent.io/courses/apache-kafka/producers
→ Kafka docs — acks producer config
Check yourself (from memory)
Q1. With acks=1 (our setting), a write is confirmed once…
acks=1 waits for the leader only —
fast, but a leader crash before replication loses that write. acks=all
would wait for the in-sync replicas.
Q2. acks is fundamentally a setting about…
acks=1 instead of the safer acks=all?acks=all interacts with min.insync.replicas
(the combo that actually guarantees durability)? Ask me — it's the
natural bridge into Lesson 7.
1. Confluent Developer — Producers.
2. Confluent — Message Delivery Guarantees; Kafka docs — acks.