Fundamentals CAP Theorem
CAP Theorem
The fundamental trade-off in distributed systems: you can only guarantee two of three properties.
The Three Properties
C
ConsistencyEvery read receives the most recent write or an error
A
AvailabilityEvery request receives a response (success or failure)
P
Partition ToleranceSystem continues to operate despite network partitions
The Key Insight
In practice, Partition Tolerance (P) is mandatory for any distributed system - network failures are a reality. This means your real choice is between CP (consistency over availability) and AP (availability over consistency).
Choosing Between CP and AP
CP
Choose CP when...- Wrong data causes real harm (financial transactions)
- Users expect immediate consistency (booking systems)
- You need strong guarantees (inventory counts)
- Data conflicts are hard to resolve
AP
Choose AP when...- Availability is critical (always-on services)
- Eventual consistency is acceptable (social feeds)
- You can merge conflicts automatically
- Stale data is better than no data