CAP Theorem Explained with Real-World Examples
What is CAP Theorem?
Every distributed system can only guarantee two out of three properties:
- Consistency — every read returns the most recent write
- Availability — every request gets a response (not necessarily the latest data)
- Partition Tolerance — the system continues operating even if network partitions occur
The key insight most engineers miss: partition tolerance is not optional. Networks fail. Hardware crashes. Partitions are inevitable in any distributed system operating at scale. So you're really choosing between CP and AP.
Why Partition Tolerance Isn't a Choice
When Amazon runs across multiple data centers, network partitions between those centers will happen — not if, but when. When they do, you must decide:
"Do I serve potentially stale data, or do I reject the request entirely?"
That's the real trade-off.
CP Systems — Consistency over Availability
A CP system will refuse to respond rather than return stale data.
Real world example: Banking systems. If you query your balance across two nodes that can't communicate, a CP system returns an error rather than risk showing you an outdated balance. You can't afford to show $5,000 if someone just withdrew it from another branch.
Examples: HBase, Zookeeper, etcd.
AP Systems — Availability over Consistency
An AP system will always respond, but might return slightly stale data.
Real world example: Your Twitter/X feed. If a network partition occurs, it's far better to show you a feed that's 30 seconds stale than to show you an error page. You won't notice. Nobody cares.
Examples: DynamoDB, Cassandra, CouchDB.
The Interview Answer
When asked about CAP theorem in a system design interview, the pattern that impresses is:
- Identify the domain — is data correctness critical?
- State your choice explicitly — "I'll choose AP because..."
- Address the trade-off — "This means eventual consistency, which is acceptable because..."
For a social feed: AP — availability matters more, eventual consistency is fine. For a payment processor: CP — consistency is non-negotiable. For a shopping cart: AP — better to show a slightly stale cart than an error.
Conclusion
CAP theorem isn't a theoretical concept — it's a decision framework. Every time you choose DynamoDB over PostgreSQL, you're making a CAP decision. Own that decision, articulate the trade-off, and you're thinking at Staff Engineer level.