Lesson 7 of 15
28. Consistent Hashing

28.6 How does replication work on the ring?

3 min read+10 XP

At the table: Your main host looks after you, but if they step out, the next two hosts to the right already know your order. That only works if those are different people: if a host sitting in many seats is also "your backup", you have no backup at all.

In the system: To keep N copies of each key (Chapter 14), walk clockwise from the key and pick the first N distinct physical servers. Dynamo calls this the preference list: the first is the coordinator, the rest hold replicas.

walking clockwise, skip points from servers already chosen: B, D, A, not B, B, D.

Figure: with virtual nodes, skip points that belong to servers you already have.

With virtual nodes, the next few points often belong to the same server. Taking the next N points blindly puts two "replicas" on one machine. In the chapter's code, about half of all keys end up with a duplicate replica that way (the Level 4 bug); skipping already-chosen servers fixes it.

Real systems go further:

  • Skip servers in the same rack or availability zone, so one power or network failure can't take all copies.
  • Combine with quorums (Chapter 14): write to W of the N replicas, read from R, with W + R > N for overlap.
  • When a server is down, a write can go temporarily to the next healthy server (hinted handoff) and be passed back later.

Memory code: "Your backups are the next different hosts, not the same host in another seat."