04
Deep dive — sloppy quorum
Strict quorum says: writes must go to W of the N home replicas. If a network partition isolates them, writes fail. Good for correctness, bad for availability.
Sloppy quorum (Dynamo): if the home replicas are unreachable, write to any W healthy nodes, marking them as temporary holders. When the network heals, hinted handoff transfers the data back to the real home replicas.
Result: writes keep succeeding during partitions. Reads from the home replicas might temporarily miss recent writes (they're on the temporary holders). Availability ↑, consistency temporarily ↓. Cassandra and DynamoDB both default to sloppy quorum — it's the reason they feel always-up during AWS regional incidents.
Interview answer
"We use quorum reads/writes: W=R=⌈(N+1)/2⌉=3 of N=5 replicas. This guarantees read-your-writes strongly. For latency-critical reads on low-stakes data (e.g. engagement counters), we drop to R=1, accepting eventual consistency."
Quorum N/R/W (Dynamo-style)
# N = total replicas, R = read quorum, W = write quorum
# Consistency iff R + W > N
def write(key, value, replicas, W):
acks = 0
for r in replicas:
try:
r.put(key, value)
acks += 1
if acks >= W: return "ok"
except Exception:
pass
return "failed" if acks < W else "ok"
def read(key, replicas, R):
results = []
for r in replicas:
try: results.append(r.get(key))
except: pass
if len(results) >= R: break
# Return value with latest vector clock; trigger read-repair for stale
return max(results, key=lambda x: x.version) if results else None
# N=3, R=2, W=2 → tolerates 1 failure per op; strong consistency.
# N=3, R=1, W=3 → fast reads, slow writes.
# N=3, R=1, W=1 → eventual consistency.