Introduction to the CAP Theorem
What you'll learn: You'll understand the three fundamental properties the CAP theorem defines and why distributed systems can only guarantee two simultaneously.
The Three Properties
The CAP theorem, proposed 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. Think of it like a single source of truth—if one user updates a value, everyone instantly sees that update.
Availability (A)
Every request receives a (non-error) response, without guaranteeing it's the most recent data. The system remains operational and responsive even if some nodes fail. It's like a store that's always open, even if inventory counts might be temporarily out of sync.
Partition Tolerance (P)
The system continues to operate despite network partitions—when communication breaks between nodes. In real-world distributed systems, network failures will happen, making partition tolerance essentially mandatory.
Why Only Two?
Imagine a network partition splits your database into two halves. You must choose:
- CP (Consistency + Partition Tolerance): Reject requests to inconsistent nodes to maintain correctness. Some nodes become unavailable.
- AP (Availability + Partition Tolerance): Accept requests on both sides, risking temporary inconsistencies until the partition heals.
You can't have CA (Consistency + Availability) in a truly distributed system because network partitions are inevitable—you can't ignore partition tolerance.
This isn't about theoretical impossibility in perfect conditions; it's about real-world trade-offs when networks fail, which relates directly to the partial failures and network partitions you've already learned about.
Key Takeaway: The CAP theorem forces distributed systems to choose between consistency and availability during network partitions, since partition tolerance is non-negotiable in real distributed environments.