Brokers and replication
Brokers are Kafka's servers; each partition is copied to several of them, with one leader and in-sync followers, so a broker can fail without losing committed data.
Diagrams in this video · 1Free in archhy
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
After this lesson you can
- Say what a broker and a replica are
- Explain leaders, followers and the in-sync replicas
- Describe what happens when a leader's broker fails
- Explain why broker defaults aren't production defaults
Transcript
Brokers and replication
Space Llama here. So far, partitions have floated in space. Today, they land on servers. Brokers, and how Kafka keeps copies, so one failure doesn't lose your data. Grab a coffee. This one's about keeping data safe.
Brokers and replicas
A broker is a Kafka server. A cluster has several of them, and the partitions are stored on them. Replication is per partition. Each partition is copied to several brokers, and each copy is called a replica. This is core Apache Kafka, so it works the same wherever you run it. The replication factor is how many copies there are. Three is a common production setting. Three copies means one leader and two followers. Let's see what each one does.
A broker fails
Here's one partition, P zero, with a replication factor of three, spread over three brokers. One replica is the leader. The producer writes to the leader, here on broker two. The other replicas are followers. They fetch every write from the leader, much as a consumer would. Followers that have caught up are in sync. Together they're the ISR, the in-sync replicas. A write is committed once every in-sync replica has it. Now broker two fails. The leader is gone, but two in-sync copies are still there. The controller spots the failure, and elects a new leader from the remaining in-sync replicas. Here, the follower on broker one takes over. By default, Kafka won't pick a replica that's behind. It waits for a consistent one instead.
Defaults vs a durable setup
Here's a trap. Kafka's broker defaults are tuned for one developer's machine, not for production. By default, a new topic gets one copy, the minimum in-sync replicas is one, and topics are created automatically the first time they're used. A typical durable setup is three replicas, a minimum of two in sync, and producers sending with acks set to all. Then one broker can fail, and writes keep going. If too few replicas are in sync, the producer gets a NotEnoughReplicas error instead. We'll work through that example properly in part three.
What acks all really means
One more trap. Acks all sounds like every replica has your write. It actually means every replica that's in sync right now. The leader keeps track of that list. With the default minimum of one, a write can count as committed when only the leader has it. That's why the minimum matters. Pair acks all with a minimum of two in sync, and every committed write is on at least two brokers.
Consistency first
There's a setting behind that failover choice, called unclean leader election. It's off by default. Kafka favors waiting for a consistent replica over staying available with one that's behind.
Remember
Let's recap. Brokers are Kafka's servers. Each partition has a leader and followers on different brokers. A write is committed once every in-sync replica has it, and an in-sync follower takes over if the leader fails. And the broker defaults aren't production settings. Set durability yourself.
Practice and what's next
Next lesson, KRaft. Who runs the cluster itself, now that ZooKeeper is gone. See you there.
Gazeek Flash · free
Exam questions on your phone
Free questions on How Kafka holds events: quick-fire batches and timed exams, on the web or Android.





