Skip to content
BENIBIX Learn

Kafka Replication Factor

Also known as Replication Factor, Topic Replication Factor

Kafka keeps more than one copy of each partition. This number says how many.

Think of it like

It is like giving three friends a copy of your house key. Lose one, and you still get in.

Example

Emma's topic has a replication factor of 3 across three brokers. One broker fails in the night, and no event is lost.

Why it matters

Machines fail. Copies on other brokers are what keep a failure from losing events.

Definition

The replication factor is how many copies of each partition Kafka keeps. Each copy sits on a different broker. One copy is the leader and takes the writes. The others follow it. If the leader's broker dies, a follower takes over. A factor of 3 is a common setting in real use, while a factor of 1 means one dead machine can lose data.

Example code

console
$ bin/kafka-topics.sh --create --topic orders --partitions 3 \
    --replication-factor 3 --bootstrap-server localhost:9092
Three partitions, and each one is kept on three brokers.
The bottom row is a replication factor of 3. The leader takes writes and two brokers keep copies.

Common mistake

Leaving it at 1 for real data. One broken disk then means lost events.

Key takeaways

  1. 1
    Copies. Each partition, several times.
  2. 2
    Leader and followers. One takes writes, the rest follow.
  3. 3
    Three is common. Survives losing a broker.