The CAP Theorem: Consistency, Availability, and Partition Tolerance
You'll learn: Why distributed systems must make trade-offs between consistency, availability, and partition tolerance—and can only guarantee two of the three simultaneously.
What is the CAP Theorem?
The CAP theorem, formulated by Eric Brewer, states that any distributed data system can provide at most two out of three guarantees:
- Consistency (C): Every read receives the most recent write or an error. All nodes see the same data at the same time.
- Availability (A): Every request receives a response (success or failure), without guarantee that it contains the most recent data.
- Partition Tolerance (P): The system continues to operate despite network partitions (communication breakdowns between nodes).
Why Only Two?
Think of a distributed database with nodes in different data centers. When a network partition occurs (the connection breaks), you face a hard choice:
Scenario: A write happens on Node A, but Node B can't receive it due to the partition.
- Choose CP (Consistency + Partition Tolerance): Reject reads/writes on Node B until the partition heals. You maintain consistency but sacrifice availability.
- Choose AP (Availability + Partition Tolerance): Allow Node B to serve potentially stale data. You maintain availability but sacrifice consistency.
You cannot achieve both CA (Consistency + Availability) in a truly distributed system, because network partitions are inevitable in real-world scenarios—you must be partition-tolerant.
Practical Reality
Modern distributed systems typically choose between CP and AP based on business requirements:
- CP systems: Banking systems, inventory management (sacrifice availability during partitions)
- AP systems: Social media feeds, analytics dashboards (serve stale data rather than error)
Key Takeaway: The CAP theorem forces distributed systems to trade off between consistency and availability when network partitions occur—understanding this helps you make informed architectural decisions based on your application's priorities.