Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 of 7
  1. 1. One copy is not enough
  2. 2. Three ways to say yes
  3. 3. Slow the network and kill the leader
  4. 4. When a leader crash loses acknowledged writes
  5. 5. What the replication log actually contains
  6. 6. How a follower falls hours behind
  7. 7. Check the failover and lag cases

Topic 2

Three ways to say yes

6 min read

The acknowledgement rule

The leader has one decision to make for every write. How many copies must exist before it tells the client the write succeeded? There are three common answers.

Asynchronous. The leader tells the client yes as soon as the write is on its own disk. The followers get it afterwards. This is the fastest, and the client’s wait does not depend on the network at all.

Semi-synchronous. The leader waits until one follower has the write, then says yes. Now every acknowledged write exists on two machines.

Synchronous. The leader waits for every follower. Every acknowledged write exists everywhere.

The stepper walks one write through all three. The delays in it are made up to keep the arithmetic easy. The lab has the real thing.

One write, three rules for when to say yes

Step 1 / 5
LeaderFollower 1Follower 2
leader log
4 entries
followers
3 and 3
  1. The write reaches the leader

    The leader appends the fourth entry to its log. Followers still hold three. Say the link to follower 1 takes 10 ms one way and the link to follower 2 takes 40 ms.

What each rule costs

A client waiting on a follower waits for a round trip, there and back. So the wait is the delay to the follower and the delay of its reply. With several followers the leader waits for the fastest one in the semi-synchronous case and for the slowest in the synchronous one.

That sets up the trade. A stricter rule means more copies before the client is told yes, which means a smaller window for lost writes and stale reads, which means slower writes. One slow or dead follower also stalls every write under the synchronous rule. Real systems rarely run fully synchronous for that reason. Semi-synchronous, where one follower is kept up to date and the rest follow, is a common compromise.

When the leader dies

If the leader fails, one follower is promoted. This is failover. The sensible choice is the follower that is furthest ahead, since it has the most data. Whatever the new leader never received is gone.

The danger depends on the rule. Under the asynchronous rule the client may have been told yes for a write that no follower has. Under the semi-synchronous rule an acknowledged write is on at least one follower, so promoting the furthest-ahead survivor keeps it, unless that follower was lost along with the leader. Under the synchronous rule every follower has it.

Keeping one user’s view sensible

Even when lag is unavoidable, some things can be promised to a single user. Two are worth knowing by name. Both come from the session guarantees in the Terry paper.

Read-your-writes. A user who writes something should see it on the next read. The usual fix is routing. If a read would land on a follower that has not yet applied this user’s last write, send it to the leader instead. A user can carry a token, such as the log position of their last write, so any node can check whether it is far enough along.

Monotonic reads. A user who has seen a value should never later see an older one. This breaks when consecutive reads hit different followers with different lag. One fix is to pin each user to one follower, since one follower only moves forward. A stronger fix uses the same token idea and also tracks the newest position the user has read.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms