The Leader and Follower Pattern
Overview
In the Redundancy and Replication chapter you saw that copies of data keep a system safe. The leader-follower pattern is the most common way to organise those copies: one node is in charge of writes and the rest copy it.
This gives one clear order of changes and lets the followers share the read load.
Detailed Notes
What is leader and follower
One node is the leader (also called primary or master). It is the only node that accepts writes. The other nodes are followers (replicas or secondaries). They receive a copy of every change from the leader and can serve reads.
The problem it solves
If every copy could accept writes, two users might update the same row on two different nodes at the same moment, and the copies would disagree. Resolving such conflicts is hard. With a single leader, all writes pass through one place, so there is one agreed order of changes and no conflicts.
It also solves read load: a popular site reads far more than it writes, so followers can answer reads while the leader focuses on writes.
How it works
- A client sends a write to the leader.
- The leader applies it and records it in a replication log, an ordered list of changes.
- The log is shipped to every follower.
- Followers apply the entries in the same order, so they end up identical.
The key choice is when the leader says "done" to the client (the synchronous and asynchronous trade-off from the previous chapter):
- Synchronous: the leader waits for followers to confirm. No acknowledged write is lost, but writes are slower and a down follower can block them.
- Asynchronous: the leader confirms after its own local write. It is fast, but if the leader crashes, the latest writes may be lost.
Many systems use a middle path: wait for one follower and let the rest be asynchronous.
Because async followers trail slightly, they can be a little behind (replication lag). A user might save a profile and then read it from a lagging follower and see the old value. Common fixes: after a user writes, read from the leader for a short time, or only read from followers that have reached the user's write position (this is called read-your-writes).
A simple example
A class has one teacher writing on the board (the leader) while students copy it into notebooks (followers). Only the teacher decides what goes on the board, and a student who copies a few seconds late is "lagging."
System design example
An online store has one primary database and three read replicas. Writes such as orders go to the primary. Product browsing reads come from replicas. During a sale a replica falls a few seconds behind, so the browse page shows a slightly old stock number, which is acceptable. The checkout step re-checks stock on the primary, so nobody buys a sold-out item. The team traded freshness on browse pages for scale, while keeping correctness where it matters.
Note that followers raise read capacity only; every write still goes through one leader, so write throughput does not grow (that needs partitioning, from the Data Partitioning chapter).
Summary
- One leader takes all writes; followers copy its replication log and serve reads.
- A single writer gives one agreed order and avoids conflicts.
- Synchronous replication is safer but slower; asynchronous is faster but can lose recent writes.
- Followers can lag, so route reads that need fresh data to the leader.
Architecture Diagram
Writes go to the leader; its log is copied to followers that serve reads.
- 1A client sends a write to the leader.
- 2The leader applies it and appends it to its replication log.
- 3The log entry is shipped to each follower.
- 4Followers apply entries in the same order and can serve reads.
Common Interview Questions
Finished this lesson?
0 of 91 lessons done · 0% of the course

