Skip to main content

How Kafka Replication Works: A Beginner's Guide

· 10 min read
OSO Engineering
The team behind OSO Kafka Backup

How Kafka replication works in one sentence: Kafka copies each topic partition to several brokers, one copy leads, and the others follow, ready to take over. When the broker holding the leader copy fails, a follower becomes the new leader and clients carry on. That single idea is why a Kafka cluster survives dead disks and crashed machines without losing acknowledged data.

This guide is for readers meeting replication for the first time. It builds the mental model piece by piece: the vocabulary, the journey of one message, what happens during a broker failure, and a topic you can create yourself to watch it all work.

Key takeaway

Replication is copies of a partition on different brokers. One copy is the leader, the rest follow it, and Kafka promotes a follower when the leader's broker dies. It protects against machine failure — not against deletes, bad writes, or anything else that replicas copy just as faithfully.

The building blocks: topics, partitions, and replicas

A Kafka topic is not stored as one big log. It is split into partitions, and each partition is an ordered, append-only log of records. Partitions are how Kafka spreads a topic's load across many brokers.

The partition is also the unit of replication. When a topic has a replication factor of three, every one of its partitions exists as three copies — three replicas — each on a different broker. One replica is the leader; producers send every write to it. The other replicas are followers; they copy the leader's log and wait.

TermWhat it isWhy it matters
PartitionAn ordered log holding part of a topic's recordsThe unit of parallelism and of replication
ReplicaOne broker's copy of a partitionMore replicas survive more broker failures
LeaderThe replica that accepts all writes for a partitionIts broker failing is the event replication exists for
FollowerA replica that copies the leader's logThe pool of ready replacements
Replication factorTotal number of replicas, leader includedSets how many copies exist
In-sync replicas (ISR)The replicas proven to be up to dateOnly these can be promoted to leader
Committed recordA record every in-sync replica has storedThe only kind consumers are allowed to read

In the simple mental model, both writes and reads go through the leader. Newer Kafka versions can also serve reads from a follower in the same rack or availability zone, but that is an optimization you can ignore while learning.

Leadership is spread around deliberately. With three brokers and a three-partition topic, each broker typically leads one partition and follows two. No single broker leads everything, so no single failure disturbs everything.

How Kafka replication works, one message at a time

The fastest way to understand how Kafka replication works is to follow one record through a small cluster. Say you run three brokers and a topic named orders with three partitions and a replication factor of three. A customer places an order, and your producer sends the event.

First, the producer picks a partition — say partition 0 — and looks up its leader in the cluster metadata. Broker 1 leads partition 0, so the record goes to broker 1. The leader validates the record and appends it to the end of its local log.

Next, the followers on brokers 2 and 3 fetch that record from the leader. There is no special push channel: the Kafka design documentation describes followers consuming from the leader just as a normal consumer would. They pull batches of records and append them in exactly the same order, so every copy of the log stays identical.

Once every in-sync replica has stored the record, it counts as committed. Consumers only ever read committed records. That rule matters more than it first appears: a consumer can never see a record that exists only on the leader, so a crash and failover can never make data a consumer already read disappear.

The producer, meanwhile, chooses how long to wait through its acks setting. It can fire and forget, wait for the leader's append, or wait until the full in-sync set has the record. Those settings, and the min.insync.replicas floor that backs them, are the practitioner's dials — the full Kafka replication guide covers how to set them safely.

What happens when a broker fails

Now the payoff. Broker 1 — the leader for partition 0 — loses power. Its heartbeats to the cluster's controller stop, and the controller declares it gone.

The controller then picks a new leader for partition 0 from the in-sync replicas: the followers that were provably up to date when the broker died. Brokers 2 and 3 both qualify, so one of them — say broker 2 — becomes the new leader. Producers and consumers refresh their metadata, find the new leader, and continue. The interruption is a short pause, not an outage.

Committed records survive this completely. Every record a producer was told succeeded already existed on the in-sync followers, so the new leader has all of them. Kafka's guarantee is that committed records are not lost while at least one in-sync replica stays alive.

What makes a follower "in sync"? Two things, roughly: its broker holds an active session with the controller, and it has kept up with the leader's log within a configured window (replica.lag.time.max.ms). A follower that falls behind drops out of the set until it catches up. The in-sync replicas guide walks through the mechanics.

One edge case is worth knowing early. If every in-sync replica for a partition dies, Kafka by default waits for one of them to come back rather than promoting a stale follower that would silently lose records — a tradeoff controlled by unclean.leader.election.enable. And when the failed broker eventually returns, it re-syncs its log from the current leader and rejoins the in-sync set as a follower.

Try it: create a replicated topic and read the output

Watching replication assign itself is a five-minute exercise on any test cluster. Create a topic with three partitions and three copies of each:

bin/kafka-topics.sh --bootstrap-server localhost:9092 \
--create --topic orders \
--partitions 3 --replication-factor 3

Then ask Kafka to describe it:

bin/kafka-topics.sh --bootstrap-server localhost:9092 \
--describe --topic orders

Each partition prints a line like this:

Topic: orders  Partition: 0  Leader: 1  Replicas: 1,2,3  Isr: 1,2,3

Read it as: broker 1 currently leads partition 0, brokers 1, 2, and 3 hold copies, and all three copies are in sync. A healthy topic shows the same broker list in Replicas and Isr. If Isr is shorter than Replicas, a copy has fallen behind — the under-replicated partitions guide covers diagnosing why.

What replication protects — and what it cannot

Replication has one job: keep a partition available and its committed records safe when brokers fail. Each extra replica, placed on separate hardware, buys tolerance for one more simultaneous failure. That is real protection, and production clusters should never run critical topics without it.

But followers copy the leader's log exactly, and that fidelity cuts both ways. Delete a topic, and every replica deletes it. Ship a bug that writes garbage for four hours, and every replica stores the garbage in perfect order. Retention works the same way: when a record expires, it expires from all copies. Replication is not backup, because replicas cannot rewind to the state before a mistake.

Native replication also never leaves the cluster. Copying topics into a second cluster — for another region, or a standby — is a separate discipline with its own tools, covered in the Kafka geo-replication guide. And keeping an independent, restorable copy outside Kafka entirely is what backup tools do: the disaster recovery use case shows how point-in-time restore complements the availability replication provides, and the comparison of alternatives maps which tool covers which failure.

Where to go next

You now hold the beginner's mental model: partitions are the unit, one leader takes writes, followers pull copies, and failover promotes an in-sync follower. From here, follow the practitioner path:

Add the layer replication can't provide

Replication keeps Kafka available; it cannot rewind a delete or a bad deploy. Kafka Backup adds independent, point-in-time restorable copies of your topics and consumer offsets — start with the disaster recovery use case.

Frequently asked questions

What is a replica in Kafka?

A replica is one broker's copy of a topic partition. Each partition has a single leader replica that accepts all writes and zero or more follower replicas that copy the leader's log. The replication factor sets how many replicas exist in total, including the leader.

How does Kafka replicate partitions?

The topic partition is Kafka's unit of replication. Follower replicas fetch records from the partition leader much like an ordinary consumer, then append them to their own logs in identical order. A record counts as committed once every in-sync replica has stored it, and consumers only read committed records.

How does Kafka handle data partitioning and replication?

A topic is split into partitions, and each partition is copied to multiple brokers. Partitioning provides scale: records spread across partitions, and different brokers lead different partitions. Replication provides safety: if the broker leading a partition fails, an in-sync follower on another broker is promoted and clients continue.

Does Kafka replicate messages to each cluster?

No. Kafka's built-in replication copies partitions between brokers inside a single cluster only. Copying topics to a second cluster requires a separate replication tool such as MirrorMaker 2, and protecting data against deletes or corruption requires an independent backup outside the cluster.

Wrapping up

Kafka replication works by keeping several copies of every partition and letting the in-sync followers stand in for a failed leader. It is the reason a broker can die mid-write without losing a single acknowledged record. Learn its vocabulary once — partition, leader, follower, ISR, committed — and the rest of Kafka's durability story, from replication factors to disaster recovery, becomes much easier to follow. Just remember the boundary: replication keeps the cluster up, and only a backup can take it back in time.