Sub topic 3
Resolving Conflicts and Operating Replicated Stores
Assume you know quorum replication, basic RPC, hashing, and vector clocks. This chapter connects conflict handling with routing, recovery, and operational testing.
Conflicts: last-write-wins, siblings, and CRDTs
Replicas can accept writes concurrently. A conflict-resolution strategy decides what readers see.
- Last-write-wins (LWW) keeps the value with the greatest timestamp. It is simple, but clock skew can discard a valid write.
- Siblings preserve concurrent versions. The application or a later merge operation chooses the final value.
- A CRDT is a data structure whose merge operation produces the same result regardless of message order. For example, a grow-only set can merge by taking the union.
def lww(values):
"""values contains (timestamp, value) pairs."""
return max(values, key=lambda item: item[0])
print(lww([(10, "red"), (12, "blue")])) # (12, 'blue')A common error is treating a timestamp as proof of causality. Vector clocks identify whether updates are ordered or concurrent; physical time does not.
Gossip, routing, and temporary failures
Gossip spreads membership and health information between randomly selected nodes. Failure detectors use missed heartbeats and suspicion timeouts. Because gossip is eventually consistent, routing decisions can briefly disagree.
A request can use a coordinator, which receives the operation and forwards it to the key’s preference-list replicas. With client-side routing, the client computes the partition and contacts replicas directly. Coordinators simplify clients but add a network hop.
Sloppy quorum writes to reachable nodes outside the normal preference list when an intended replica is down. Hinted handoff stores a hint saying where that data belongs. When the target returns, the hint is delivered. Hints need expiration and durable storage so temporary overload does not become permanent data loss.
Repair, consensus, and testing
Read repair fixes replicas when a read discovers different versions. Merkle-tree anti-entropy compares hashes of key ranges, then synchronizes only differing ranges. Both mechanisms limit long-term divergence.
Raft and Paxos use consensus to agree on an ordered log, usually through a leader. This gives stronger, easier-to-reason-about consistency than leaderless quorums, but requires a majority for progress and adds coordination latency.
Test operations by injecting node crashes, packet loss, delays, clock skew, duplicate messages, and disk-full errors. Verify acknowledged writes, repair completion, conflict behavior, quorum timeouts, and recovery after repeated failures. Monitor replica lag, hint counts, repair duration, and membership changes.
Exercise
Why does a read repair process not replace anti-entropy?
Show answer
Read repair only examines keys that clients read. Anti-entropy also finds divergence in cold keys.