CAP theorem
The notes
The three components
The CAP theorem states that in a distributed system you can only guarantee two out of three properties: consistency, availability and partition tolerance. This constraint shapes how distributed databases and systems are designed.
C: Consistency
- All nodes see the same data at the same time
- When data is written, all subsequent reads return that value across all nodes
- Every client sees the most recent write
A: Availability
- Every request receives a response (success or failure), even if some nodes are down
- The system remains operational and accessible, though data may not be the latest
P: Partition tolerance
- The system continues to operate despite network failures that split nodes into isolated groups
- It handles communication breakdowns between nodes gracefully
Why you can only pick two
- In a distributed system, network partitions (communication failures between nodes) are inevitable
- When a partition occurs you must choose: guarantee consistency by refusing requests to some nodes (sacrificing availability), or guarantee availability by allowing potentially inconsistent data (sacrificing consistency)
- You cannot have both during a partition
- Since partition tolerance is required for any distributed system, the real choice is between consistency (CP) and availability (AP)
- CA systems are rare in practice because they assume no network partitions, which is unrealistic in distributed environments
CA: consistency and availability (rarely practical)
Prioritizes consistent data and system availability but cannot tolerate network partitions. Only works in single-location systems without partitioning.
Use case
- Traditional RDBMS in a single location with no partitions
- Specific internal applications where network splits are negligible
CP: consistency and partition tolerance (consistency first)
Ensures all nodes always have consistent data, even during network partitions. May refuse requests to maintain accuracy, temporarily reducing availability.
Use case
- Banking systems, financial transactions, inventory management
- Any system where accuracy is critical and temporary unavailability is acceptable (e.g. "Transaction cannot be processed right now")
AP: availability and partition tolerance (availability first)
The system remains available during partitions, but data may be temporarily inconsistent across nodes. Eventual consistency ensures data syncs when the partition resolves.
Use case
- Social media feeds, e-commerce shopping carts, DNS, caching systems
- Systems where showing content immediately is critical and temporary inconsistency is acceptable (e.g. "Like count may be slightly off")
Key takeaway. Partition tolerance (P) is mandatory for distributed systems, because network failures will happen. Choose between C and A based on business needs: accuracy vs continuous access. CP systems suit financial applications where wrong data is worse than temporary downtime; AP systems suit social and content platforms where the user experience requires constant access. Eventual consistency is the practical approach for AP systems: data will sync eventually.
System design deck
1. Fundamentals
2. Scaling
3. Frontend vs backend
4. Client-server architecture
5. Databases
6. Load balancer
7. Caching
8. Latency vs throughput
9. Availability and redundancy
10. CAP theorem
and many more
Make them stick
Sign in to see every card full size, tick the ones you've got, come back to the rest later, and keep your own notes on each card.
Watch the lesson
System design, Lesson 10, from 5:13: CAP Theorem