CAP Theorem â–ł
The CAP theorem states that distributed databases have to choose between consistency, availability, and partition tolerance. You can only pick two out of the three guarantees.
- Consistency: all nodes see the same data at the same time. Strict consistency.
- Availability: Every request receives a response. The system is always up.
- Partition tolerance: The system continues to operate despite network partitions.
Implications
- Can’t have all three guarantees in a distributed system
- Sacrifice consistency for availability in partition-prone systems
- Many NoSQL databases favor AP (availability and partition tolerance)
- Traditional RDBMS favor CA (consistency and availability)
- Understand tradeoffs when choosing databases
Examples
CP - Consistency and Partition Tolerance
Favors consistency over availability during a partition. Useful for systems that need strong consistency guarantees.
- Blockchain networks - need consistent ledger
- Multi-player games - need consistent state
- Financial transactions - need consistency guarantees
AP - Availability and Partition Tolerance
Favors availability over consistency during a partition.
- Web applications - need to serve users like retail websites.
- Real-time analytics - need uptime
- IoT backends - need availability for devices
CA - Consistency and Availability
No partitions allowed. Maintains both consistency and availability. Useful for systems that operate in a trusted network with no partitions expected.
- Legacy databases - no distributed partitions
- Intranet applications - controlled network
Bottom line
So in summary:
- CP prioritizes consistency in distributed systems
- AP prioritizes availability in partition-prone systems
- CA works in a trusted non-distributed environment
Choose based on application requirements. The CAP theorem implies there are fundamental tradeoffs in distributed systems.
Sources
Last updated on