Replication
Definition
Replication
- In plain English
- Replication means keeping copies of the same data on several machines.
- Think of it like
- It is like a choir where several singers know the same part, so the song continues if one loses their voice.
Leader and follower
- In plain English
- In leader-follower replication, one machine (the leader) accepts writes and copies them to followers, which serve reads.
- Think of it like
- It is like a head chef who decides each recipe change and the line cooks who copy it.
Why it exists
Your podcast catalogue has a fast index, but one database machine still handles every read. It eventually runs out of capacity.
If that machine fails, nobody can read the catalogue. Copies provide another place to serve data.
How it works
Replication lag
- In plain English
- Replication lag is the delay before a change on the leader appears on a follower.
- Think of it like
- Like news reaching a distant village a day late.
Synchronous vs asynchronous replication
- In plain English
- Synchronous replication waits for a follower to confirm before saying "done", while asynchronous replication says "done" first and copies afterwards.
- Think of it like
- Like waiting for a friend to text "got it" versus sending and walking off.
Read-your-writes
- In plain English
- Read-your-writes is a guarantee that after you change something, your own next read shows the change.
- Think of it like
- Like seeing your own post immediately after you publish it.
The app writes to a leader, which copies changes to two followers; the app sends reads to those followers.
| Question | Synchronous | Asynchronous |
|---|---|---|
| When confirm? | After required follower acknowledgement | Without waiting for follower acknowledgement |
| Leader fails? | Durably acknowledged copy can preserve confirmed writes | Uncopied confirmed writes can be lost |
| Write delay | Includes required follower delay | Does not wait for followers |
| Required follower unavailable? | Writes may wait or fail | Leader can continue confirming writes |
| Other replication shapes | Meaning | Cost |
|---|---|---|
| Multi-leader | Several leaders accept writes and share changes | Conflicting writes need resolution |
| Leaderless | Clients contact several copies without a permanent leader | Reads and writes need careful coordination |
Examples
Spread catalogue reads
Your episode listings receive 200 reads per write. Three followers serve reads while the leader stores episode changes.
One leader copies episode changes to three followers, and catalogue reads spread across all three.
For 10 writes per second, the ratio gives 2,000 reads per second. Each follower still processes the copied changes.
The insight
Followers add read capacity, subject to replication and routing costs.
Show the learner’s saved edit
You save a card, then refresh from a follower that still holds the old text.
A learner saves on the leader, receives old text from a lagging follower, then sees the edit when reading the leader.
Route the learner’s reads to the current leader after saving. A fixed few-second delay alone cannot guarantee that a follower catches up.
The insight
Read-your-writes needs deliberate routing or proof that a follower caught up.
Keep a confirmed call record
You place a required synchronous follower in a separate failure zone. It saves call changes durably before acknowledgement.
If the leader’s zone fails, promote that surviving follower. Confirmed records survive this failure when the acknowledged storage remains intact. Receipt, durable storage, and visibility to reads are different events.
Promotion means making a follower the new leader. Prevent the old leader from accepting competing writes after it returns.
This protects the stated failure case, not every disaster. Keep backups because copies also reproduce mistaken deletions.
The insight
Synchronous durable acknowledgement protects confirmed writes under a defined failure model.
Trade-offs
Pros
- Surviving copies can support recovery.
- Followers can share reads.
- Copies can be nearer readers.
Cons
- Followers may return stale data.
- Leader replacement needs coordination.
- One leader still handles all writes.
Use when
- Reads outgrow one machine.
- The service needs a surviving data copy.
Avoid when
- Adding read copies is meant to fix write capacity.
- You expect replication to replace backups.
Quick check
Takeaways
- Replication keeps copies for safety and read capacity.
- A leader accepts writes while followers copy changes.
- Account for replication lag and the exact acknowledgement guarantee.