Video in progress

What do the leader and follower replicas of a partition do?

The leader is the replica the producer writes to and (by default) the consumer reads from. Followers keep copying data from the leader, and if the leader goes down, one of them becomes the new leader.

📖 Answer

The leader of each partition is chosen separately. That's why the load is spread across brokers: one broker can be the leader for orders-0 and a follower for orders-1.

Followers pull data from the leader with fetch requests, just like a consumer does. Followers that haven't fallen behind the leader stay in the ISR (in-sync replicas) list. The new leader is chosen from that list.

kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092
# Partition: 0  Leader: 2  Replicas: 2,1,3  Isr: 2,1,3

If the Isr column shows fewer brokers than Replicas, someone has fallen behind. In monitoring, the UnderReplicatedPartitions metric shows this.

Since Kafka 2.4 a consumer can also read from the nearest follower (rack-aware fetch), but that has to be configured separately.