Loading
0x70Lesson 8 of 13

Trade consistency for availability

Apply CAP, consistency models, and quorums to replicated data.

20 min 6-question quiz 1 code exercise
By the end of this lesson you can
  • State what the CAP theorem does and does not say.
  • Match product features to consistency models.
  • Use R + W > N to reason about quorum reads and writes.

Once data is replicated across machines, the network between them can fail. The CAP theorem says that during a network partition, a system must choose between consistency (every read sees the latest write) and availability (every request gets a non-error response). Partitions are not optional in real networks, so the real choice is what to give up when one happens. PACELC extends this: else, when there is no partition, you still trade latency against consistency.

Consistency models and quorums

  • Strong (linearizable): reads always reflect the latest completed write. Needed for balances, inventory, and locks.
  • Read-your-writes / monotonic reads: weaker per-user guarantees that feel right to a single user.
  • Eventual: if writes stop, replicas converge. Fine for like counts, view counters, and feeds.

Leaderless (Dynamo-style) stores write each key to N replicas. A write succeeds after W acknowledge; a read queries R replicas and takes the newest version. If R + W > N, every read set overlaps every write set, so reads see the latest write.

design.py
1def describe(n, w, r):
2    return "overlap guaranteed" if r + w > n else "stale reads possible"
3
4print("N=3 W=2 R=2:", describe(3, 2, 2))
5print("N=3 W=1 R=1:", describe(3, 1, 1))
Output
N=3 W=2 R=2: overlap guaranteed
N=3 W=1 R=1: stale reads possible

Quorum settings are tunable: W = N, R = 1 makes reads fast but writes fragile; W = 1, R = N does the opposite. When replicas diverge, the system must reconcile. Last-write-wins is simple but silently drops concurrent updates; version vectors detect conflicts so the application can merge them; CRDTs are data types that merge automatically.

Key takeaways

  • During a partition you choose consistency or availability; without one you trade latency and consistency.

  • Match consistency to the feature - strong for money, eventual for counters.

  • R + W > N makes quorum reads see the latest write.

Lesson quiz

6 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: simulate system design building blocks

Use small Python programs to estimate capacity and simulate caches, load balancers, hash rings, and rate limiters. These exercises run locally in your browser.

Exercise 1

Check quorum configurations

+25 XP

Read a count, then that many lines of N W R. For each, print N=n W=w R=r: strong if R + W > N, otherwise N=n W=w R=r: eventual.

  • Three configurations
  • Edge cases
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Did you like the lesson? 😆👍
Consider a donation to support our work: