CAP Theorem and PACELC in Plain English
The CAP theorem and its extension PACELC explained: consistency, availability and partition tolerance, what the trade-offs mean in practice and common myths.
How consistent hashing works, why it beats modulo hashing when servers change, how virtual nodes balance load, and where it’s used in caches and databases.

When you spread data across many cache or database nodes, you need a rule for which node owns which key. Consistent hashing is the rule most large systems use, because it keeps working smoothly when nodes are added or removed.
The simple approach is node = hash(key) % N. It distributes keys evenly, until N changes. Add a fifth server to four and almost every key maps to a different node. For a cache, that means a sudden flood of misses; for a database, it means moving nearly all your data.
When a node joins, it takes over only the keys between it and the previous node. When a node leaves, only its keys move to the next node. On average, only about 1/N of keys move.
With a handful of physical nodes, positions on the ring can be uneven, leaving some nodes with far more keys. The fix is virtual nodes: each physical node is placed on the ring many times under different hashes.
import bisect, hashlib
class Ring:
def __init__(self, nodes, vnodes=100):
self.ring = sorted((self.h(f"{n}#{i}"), n) for n in nodes for i in range(vnodes))
self.keys = [k for k, _ in self.ring]
def h(self, s):
return int(hashlib.md5(s.encode()).hexdigest(), 16)
def node_for(self, key):
i = bisect.bisect(self.keys, self.h(key)) % len(self.ring)
return self.ring[i][1]
To keep copies of data, a key is stored on its owner and the next few distinct nodes clockwise. If one fails, the others still serve it, a pattern tied closely to the trade-offs in the CAP theorem.
Often somewhere between tens and a few hundred. More gives smoother balance at the cost of a larger ring to search.
No, but with virtual nodes it gets close, and it minimises data movement when nodes change.
Any fast function with good distribution. Cryptographic strength isn’t required.
Every article is edited by a human and checked against our editorial policy. Spotted a mistake? Tell us.
The CAP theorem and its extension PACELC explained: consistency, availability and partition tolerance, what the trade-offs mean in practice and common myths.
How CDNs work: edge locations, request routing, cache keys, Cache-Control headers, invalidation, origin shielding, security features and edge compute.
How distributed locks and leases work, why process pauses break naive locks, fencing tokens, Redis, ZooKeeper, etcd and database locks, and alternatives.