How do you replicate data on a consistent hash ring, and what do you have to be careful about?
Sketch your own answer first, then compare it with the one below.
A strong answer
A common scheme stores each key on its owner and on the next few nodes clockwise. A client that hashes a key can compute the whole replica set from the ring.
The main subtlety is virtual nodes. Walking clockwise to the next points may land on points of the same physical node, which would put several replicas on one machine. So the walk skips points of nodes already chosen, until it has enough distinct physical nodes. Systems that care about failure domains extend this to skip nodes in the same rack or zone.
Other points to cover:
- Which node coordinates a write, and what happens when a replica is down. Dynamo-style designs let a neighbour accept the write temporarily and hand it back later.
- Reads and writes need agreed rules about how many replicas to contact, which decides consistency and availability trade-offs.
- When membership changes, replica sets change for the affected ranges, so data has to be streamed to new owners.
Sources
- Giuseppe DeCandia, Deniz Hastorun, Madan Jampani, Gunavardhan Kakulapati, Avinash Lakshman, Alex Pilchin, Swaminathan Sivasubramanian, Peter Vosshall, Werner Vogels (2007). Dynamo: Amazon's Highly Available Key-value Store.
- Avinash Lakshman, Prashant Malik (2010). Cassandra: a decentralized structured storage system.