System Design Interview Question: Explain the CAP Theorem
Short answer: in a distributed system, when a network partition happens (nodes can't talk to each other), you must choose between consistency (every read sees the latest write, or gets an error) and availability (every request gets a non-error response, possibly with stale data).
The terms, precisely
- Consistency (C) - here it means linearisability: the system behaves as if there's a single up-to-date copy. (Different from the C in ACID.)
- Availability (A) - every request to a non-failed node gets a response.
- Partition tolerance (P) - the system keeps working despite lost messages between nodes.
Why "pick two" is misleading
Networks do fail, so partition tolerance isn't optional for a distributed system. The real choice is what to do during a partition:
- CP: refuse or delay some requests to avoid serving stale or conflicting data. Examples: systems built on consensus (etcd, ZooKeeper), banking ledgers, inventory reservations.
- AP: keep answering on both sides and reconcile later. Examples: shopping carts, social feeds, DNS, many caches.
PACELC: the fuller picture
If there's a Partition, choose A or C; Else (normal operation), choose between Latency and Consistency. Even without failures, strong consistency across regions costs round trips.
How to use it in an interview
- Decide per feature, not per system: payments need consistency; "likes" count can be eventually consistent.
- Explain the user-visible effect: "During a partition, users in region B can still read profiles but can't change their username."
- Mention techniques: quorum reads/writes, leader election, conflict resolution (last-write-wins, CRDTs).
Was this article helpful?
Comments
No comments yet. Have a question or a tip? Be the first to share it.