Course contentsShow
← System Design
Lesson 706 of 1,91919. Event Streaming PlatformsFree lesson

Leaders and Followers

Learn the leader-follower model where one broker leads writes/reads per partition while followers replicate data.

Leaders and Followers

You'll learn: How Kafka organizes read/write responsibilities per partition using a leader-follower model to ensure consistency and fault tolerance.

What Are Leaders and Followers?

In Kafka's distributed architecture, each partition has one leader broker and zero or more follower brokers. The leader handles all read and write requests for that specific partition, while followers passively replicate the leader's data to stay synchronized.

Think of it like a classroom: the teacher (leader) delivers the lesson and writes on the board, while students (followers) copy notes. If the teacher leaves, one student can step up to become the new teacher.

Why This Model?

When you learned about replication and partitions, you saw that Kafka creates multiple copies of data across brokers. But who coordinates writes? The leader-follower model solves this:

  • Single point of write coordination: The leader serializes all writes to its partition, ensuring consistent ordering
  • Read consistency: All reads come from the leader (in basic configurations), guaranteeing you see the latest committed data
  • Automatic failover: If the leader fails, Kafka automatically promotes a follower to become the new leader

How It Works

When a producer sends a message to a partition, it goes directly to that partition's leader broker. The leader appends it to its log, and followers fetch updates from the leader to replicate the data. Consumers also read from the leader by default.

Each partition has its own leader—Partition 0's leader might be Broker 1, while Partition 1's leader could be Broker 2. This distributes load across the cluster.

Key Takeaway: The leader-follower model assigns one broker per partition to handle all reads/writes (leader) while others replicate data (followers), enabling both consistency and fault tolerance through automatic failover.