Skip to content

Replication: recap and quiz

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
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.

  1. What do the replicas buy you? Read capacity, a second copy, or both. They add no write capacity. (Single-leader replication)
  2. 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)
  3. What happens to writes when a synchronous replica fails? Decide before it happens whether they wait or the system degrades.
  4. Which reads may be old? Choose per read: the primary, read-your-writes, monotonic reads, or any replica. (Stale reads)
  5. 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.
  6. 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)
  7. Who decides which replica to promote, and how quickly? Promote the most up to date one, and weigh a faster detection against false alarms.
  8. How is the old primary kept from taking writes? Fencing, and a rule that a primary without a majority stops. (Split brain)
  9. Did you test the failure? Run it, as the failure labs do, and read the numbers it gives.

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.

Question 1 of 7

A primary receives one write every 50 ms. A replica applies each write 200 ms after the primary accepts it. At most how many writes is the replica behind?

Enter a number and choose its unit.

writes
Question 2 of 7

A shop has one primary and two replicas. The primary is at its limit for writes, and the replicas are nearly idle. The team proposes to add four replicas.

What does adding replicas do for the writes?

Choose one answer.

Question 3 of 7

A primary has two replicas whose lags are 100 ms and 300 ms. Replication is synchronous: the primary waits for both replicas.

After how long is a write acknowledged?

Choose one answer.

Question 4 of 7

A user posts a comment, reloads the page, and the comment is missing. Which of these remove that symptom?

Choose every answer that applies.

Question 5 of 7

Replication is asynchronous. The primary acknowledged writes 1 to 6, and crashed. The replica you promote had applied writes 1 to 4.

What happens to writes 5 and 6?

Choose one answer.

Question 6 of 7

Writes arrive at 720 per second for 20 seconds. A replica applies 400 per second. How many writes are waiting at the end of the burst?

Enter a number and choose its unit.

writes
Question 7 of 7

A partition cuts the primary off from the other two nodes. A replica is promoted. The old primary is healthy and its clients can still reach it.

What is the danger, and what removes it?

Choose one answer.

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.