Replication: recap and quiz
The module in five sentences
Section titled “The module in five sentences”- Single-leader replication. One primary takes every write and replicas apply it in the same order, which adds read capacity and a second copy but no write capacity, and multi-leader and leaderless designs trade that order for conflicts to resolve.
- Synchronous and asynchronous. The mode decides when the client is told a write is done: at once, after one replica, or after all of them, and each wait is the lag of the replica you wait for.
- Replication lag and stale reads. A replica returns what it has applied so far, so reads can be stale, miss the reader’s own write or go back in time, and each symptom has its own fix.
- Failover and lost writes. Promoting a replica costs the writes that fail while there is no primary and the acknowledged writes the replica never received.
- Split brain and fencing. A promotion while the old primary is alive gives two primaries, and the writes of one of them are lost unless it is fenced.
How each one breaks
Section titled “How each one breaks”| Idea | What breaks | What you see | What helps |
|---|---|---|---|
| Replicas | Writes arrive faster than a replica can apply | Lag grows, and reads return old data, with no error | Faster apply, fewer writes, and a lag alert |
| Acknowledgement | A synchronous replica is slow or gone | Every write waits, or none is acknowledged | Several candidate replicas, and semi-synchronous replication |
| Reads | A read lands on a replica that is behind | Stale reads, missing own writes, reads going back in time | Route by guarantee, or read from the primary |
| Failover | The primary dies with writes not yet shipped | Writes fail for a while, then acknowledged writes are missing | Promote the most up to date replica, wait for a replica before acknowledging |
| Partition | Two nodes both act as primary | Divergent writes, then one history is discarded | Fencing, a majority rule, and telling the old primary |
A checklist for designing a replicated database
Section titled “A checklist for designing a replicated database”Each question points to the lesson that answers it.
- What do the replicas buy you? Read capacity, a second copy, or both. They add no write capacity. (Single-leader replication)
- What does an acknowledged write promise? That it is on the primary only, on one replica or on all of them, and what you pay in waiting for each. (Synchronous and asynchronous)
- What happens to writes when a synchronous replica fails? Decide before it happens whether they wait or the system degrades.
- Which reads may be old? Choose per read: the primary, read-your-writes, monotonic reads, or any replica. (Stale reads)
- How far behind can a replica get, and who is told? Watch lag in seconds and in writes, and know what happens to a replica when writes spike.
- How many acknowledged writes can you afford to lose in a failover? If the answer is none, wait for a replica. (Failover and lost writes)
- Who decides which replica to promote, and how quickly? Promote the most up to date one, and weigh a faster detection against false alarms.
- How is the old primary kept from taking writes? Fencing, and a rule that a primary without a majority stops. (Split brain)
- Did you test the failure? Run it, as the failure labs do, and read the numbers it gives.
Check your understanding
Section titled “Check your understanding”Seven questions cover the whole module. Every option is explained, whether it is right or wrong.
Replication: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”Replication copies the same data to several nodes. The next module, partitioning and sharding, splits the data across nodes, a way to spread writes over several machines. Later modules return to the questions this one raised: what a client can be promised when copies disagree, and how nodes agree on who the primary is.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.