Kafka · Core Concepts

Replicas: leader and follower

Mediumreplicaleaderfollowerreplicationfailover

Interview question

What are leader and follower replicas in Kafka, and how do they work?

How to answer

The short answer

Each has replicas (copies) on different brokers. Replication is how Kafka survives broker failure.

Leader replica

  • Handles all client writes (and typically serves reads, depending on config).
  • Appends records to its local log.
  • Other replicas copy from the leader.

Follower replicas

  • Stay as close as possible to the leader's log by fetching data.
  • Do not accept client writes.
  • Are candidates to become leader if the current leader dies.
Output
Partition 0, replication factor = 3

  broker-1: LEADER   <--- producers write here
  broker-2: FOLLOWER <--- fetches from leader
  broker-3: FOLLOWER <--- fetches from leader

Replication factor

replication.factor = 3 means 3 copies of each partition. Common production choice is 3 (tolerate one or sometimes two failures depending on min ISR settings).

Failure example

If broker-1 (leader) dies, the controller promotes an in-sync follower (say broker-2) to leader. Producers discover the new leader via metadata refresh and continue.

Why followers exist

Without followers, losing the only copy of a partition loses data (or availability). Followers make durability and failover possible.

Interview tip: "One leader per partition for writes; followers replicate; on failure a follower becomes leader."