Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. Replicas: leader and follower

Kafka · Core Concepts

Replicas: leader and follower

Mediumkafka-08
replicaleaderfollowerreplicationfailover

Question

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

Solution

Each partition 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.
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 three 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."

PreviousNext