Sub topic 13
Surviving temporary failures with sloppy quorums and hinted handoff
This chapter assumes you have read the earlier chapters on consistent hashing, preference lists, and read and write quorums. You should know that each key has a replica set of N nodes, and that a write succeeds once W of them acknowledge it. You should also be comfortable reading short Python snippets.
The problem: a strict quorum fails when replicas are down
Suppose N = 3, W = 2, and a key's preference list is node-a, node-b, node-c. If node-b and node-c are unreachable, only one of the three replicas can acknowledge the write. A strict quorum design must reject the write, even though the cluster has many healthy nodes.
Many failures are short. A node restarts, a network link flaps, or a garbage-collection pause makes a node look dead for a few seconds. Rejecting writes for these events hurts availability for something that fixes itself.
Sloppy quorums and hinted handoff address this. The write still goes through, and the data is moved to its proper home once the failure ends.
Strict quorums versus sloppy quorums
A strict quorum counts acknowledgements only from the first N nodes in the key's preference list. A sloppy quorum counts acknowledgements from the first N healthy nodes found while walking the ring. Those nodes may include nodes outside the key's normal replica set.
The ring walk is the same one used to build the preference list. The coordinator keeps walking clockwise and skips nodes it believes are down. It stops when it has N healthy nodes.
| Property | Strict quorum | Sloppy quorum |
|---|---|---|
| Nodes that can acknowledge a write | Only the key's N home replicas | Any N healthy nodes along the ring |
| Write availability during failures | Lower | Higher |
| Does R + W > N guarantee overlap? | Yes, for the home replicas | No |
| Extra mechanism needed | None | Hinted handoff |
How hinted handoff works
When the coordinator writes to a stand-in node instead of a failed home node, it attaches a hint. The hint names the intended recipient. The stand-in stores the data in a separate hint store, not in its normal key space, and does not serve it to ordinary reads for its own keys.
The stand-in then checks periodically whether the intended node has come back. Membership information from gossip, covered in the earlier chapter, usually tells it. When the home node is reachable again, the stand-in sends the hinted writes to it. After the home node acknowledges them, the stand-in deletes its copies.
A runnable sketch
The sketch below extends the ring from the earlier chapter. It builds a sloppy preference list: the first N nodes that are healthy, plus a record of which home node each stand-in is covering.
import bisect
import hashlib
def h(key: str) -> int:
return int.from_bytes(hashlib.md5(key.encode()).digest()[:8], "big")
class Ring:
def __init__(self, nodes, vnodes=64):
self._points = sorted(
(h(f"{node}#{i}"), node) for node in nodes for i in range(vnodes)
)
self._hashes = [p[0] for p in self._points]
def walk(self, key: str):
"""Yield distinct nodes clockwise from the key's position."""
start = bisect.bisect(self._hashes, h(key)) % len(self._points)
seen = set()
for i in range(len(self._points)):
node = self._points[(start + i) % len(self._points)][1]
if node not in seen:
seen.add(node)
yield node
def preference_list(self, key: str, n: int):
result = []
for node in self.walk(key):
result.append(node)
if len(result) == n:
break
return result
def sloppy_targets(ring: Ring, key: str, n: int, down: set):
"""Return a list of (target, hint_for) pairs.
hint_for is None when the target is a home replica,
or the name of the down home node the target is covering.
"""
home = ring.preference_list(key, n)
missing = [node for node in home if node in down]
targets = [(node, None) for node in home if node not in down]
for node in ring.walk(key):
if len(targets) == n:
break
if node in home or node in down:
continue
targets.append((node, missing.pop(0)))
return targets
ring = Ring(["node-a", "node-b", "node-c", "node-d", "node-e"])
print("home: ", ring.preference_list("user:42", 3))
print("sloppy:", sloppy_targets(ring, "user:42", 3, down={"node-b"}))If the key's home list contains a node in down, the output shows one extra node paired with the name of the node it is covering. If no home node is down, every hint is None.
A real hint store holds more than the target name. Each hint keeps the key, the value, the version (vector clock), and the creation time, so delivery preserves causality.
What you give up: the consistency cost
A sloppy quorum weakens the overlap guarantee. With a strict quorum and R + W > N, a read quorum and a write quorum must share a replica. With a sloppy quorum, a write may be acknowledged by W nodes that are not home replicas. A later read may query the home replicas, which do not have the write yet. The two sets can be disjoint even though R + W > N.
This means a sloppy quorum gives you "always writable", not stronger consistency. Reads can return stale data until hints are delivered or other repair mechanisms run.
Hinted writes still need versions. When the home node receives a hint, it merges it like any other write. If the node already has a concurrent value, the vector clock comparison from the earlier chapter decides whether to overwrite or keep siblings.
Failure modes and edge cases
Hinted handoff is a best-effort mechanism. These are the cases to plan for:
- The stand-in fails before delivering. The hint is lost along with the node's disk, or stays unavailable until that node returns. The write was acknowledged, but fewer real copies exist than the client assumed. Anti-entropy repair, covered in the next chapter, closes this gap.
- The outage is long. Hints accumulate. If a node is down for hours, stand-ins may fill their disks. Real systems cap hint storage and time. After the limit, they drop hints and rely on repair when the node returns permanently or is rebuilt.
- Delivery storms. When a node comes back, many stand-ins may send hints at once, and the recovering node must also serve traffic. Throttle hint delivery and spread it out.
- Flapping nodes. A node that goes up and down repeatedly causes hints to be created and delivered over and over. A failure detector with sensible thresholds reduces this churn.
- Permanent removal. If a node is replaced and will never return, hints addressed to it must be discarded or redirected. Decommissioning should be an explicit step, not something inferred from a timeout.
- Misjudged failure. The coordinator may think a node is down when it is only slow. Then both the stand-in and the home node may receive writes, which is safe only because versions let the system merge them.
Decision criteria
Use a sloppy quorum with hinted handoff when write availability matters more than read freshness. Shopping carts and session data are common examples. A rejected write is visible to the user, and a briefly stale read often is not.
Prefer a strict quorum when stale reads are costly, such as for inventory counts or uniqueness checks. There you accept that writes fail when too many home replicas are unreachable. If you need stronger guarantees than quorums can give, the consensus chapter shows the alternative.
Many systems make this a setting. You can run a strict quorum for some operations and a sloppy quorum for others, and you can turn hinted handoff off per table or per cluster.
Common mistakes
- Treating a hint as a durable replica. A hint is a promise to deliver, and it is only as safe as the stand-in node. Count it toward W for availability, but do not count it as a full home replica for durability.
- Storing hints in the normal key space. Stand-in nodes would then serve the data as if they owned it, and the hints would be hard to find and clean up.
- Forgetting version metadata. If hints lose their vector clocks, delivery can overwrite newer data.
- Never expiring hints. Without a limit, a dead node can fill the cluster's disks.
Exercise
A cluster uses N = 3, W = 2, R = 2. The home replicas for a key are A, B, and C. Nodes B and C are down, and node D is healthy and next on the ring. A client writes the key with a sloppy quorum, and the write is acknowledged by A and D. Before any hint is delivered, a read is sent to B and C after they recover. Does the read see the write? Why or why not, and what makes the data eventually reach B?
Show answer
Not necessarily. B and C never received the write, because only A (a home replica) and D (a stand-in holding a hint for B or C) stored it. The read quorum {B, C} does not intersect the write set {A, D}, even though R + W > N. The data reaches B through hinted handoff when D delivers its hint, or through read repair or Merkle-tree anti-entropy if the hint is lost. Note that D holds one hint, so C still lacks the write until repair or another copy reaches it.
Exercise
Name two limits a production hint store should enforce, and the reason for each.
Show answer
Limit the time a hint may be kept and the total storage hints may use. Without these limits, a node that is down for a long time causes stand-ins to accumulate hints until their disks fill, which can harm healthy nodes. After the limit, the system drops hints and relies on anti-entropy repair.