AI Hints
Home›System Design Tutorial›Hot Spots and CAP
System Design · Lesson 47 of 120

The CAP Theorem

Pick two, really one.

⏱ 2 min read▶ Video at 55:27🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

When data lives on several machines, the network between them can break. The CAP theorem says what you can promise when it does.

The CAP Theorem
From the video: The CAP Theorem
  • Data on many machines
  • Networks can break
  • What can you promise?

C, A and P

C is consistency. Every read sees the latest write. A is availability. Every request gets an answer. P is partition tolerance. The system keeps going even when machines can't reach each other. Networks do fail, so P isn't optional. The real choice is what to give up during a failure, C or A.

LetterPromise
C: Consistencyevery read sees the latest write
A: Availabilityevery request gets an answer
P: Partition tolerancesurvives a broken network

CP or AP

So when the network splits, you choose. ACP system refuses some requests, rather than return old data. Banks and stock levels often want this. An AP system answers everything, even if some answers are a bit out of date. Social feeds and like counts are fine with that.

CP: correct or nothing

  • May refuse requestsNever stalePayments, stock

AP: always answer

  • Always respondsMay be staleFeeds, likes, carts

Summary

CAP says that during a network split, you must choose consistency or availability. Pick per feature, based on what being wrong would cost. Next, the range of consistency between those extremes.

Key takeaways
  • Partitions happen
  • Choose C or A
  • Decide per feature
Next up: Consistency Models — strong to eventual