While studying system design, I came across something called CAP theorem.
At first, it sounded simple:
A distributed system can choose any two out of Consistency, Availability, and Partition Tolerance.
But the more I read about it, the more I realized that this explanation can be a little misleading.
So I tried to understand it through a simple real-world example: a single restaurant inventory with two branches.
What is CAP theorem?
CAP theorem describes fundamental trade-off that exists in distributed systems. It was introduced by Eric Brewer in 2000.
CAP stands for:
C - Consistency
A - Availability
P - Partition Tolerance
But before understanding the theorem, let's understand what these three terms actually mean.
Suppose you have a restaurant named PizzaPazi having two branches and sharing a single inventory.
- Consistency - A customer buys the last Pizza from Branch A. Branch A knows Pizza left = 0. For system to be consistent, Branch B should also reflect the latest state.
In simple terms:
All nodes should agree on the current state of the data.
- Availability - Now imagine, Branch A is temporarily unavailable. Should Branch B also stop serving customers? -> Not necessarily. Branch B should continue responding to requests.
That's Availability:
The system continues responding to requests even when some parts of the system in unavailable.
- Partition Tolerance - Due to some reasons, the network connecting A and B breaks. Both branches are running, but they cannot communicate. This is a network partition.
Partition Tolerance means:
The distributed system continues operating despite nodes being unable to communicate with each other.
Where does the CAP problem come in?
Suppose Branch A sells the last Pizza while the network is down.
Branch A -> 0 available
Branch B -> 1 available
A customer now asks Branch B for the Pizza.
Branch B has a choice:
- Stop and wait for Branch A → preserve the latest consistent state.
- Continue serving the customer → remain available, but potentially use stale data.
And that's the core idea of CAP:
** When a network partition occurs, you cannot guarantee both Consistency, and Availability at the same time.**
The biggest thing I learned is that CAP isn't just about memorizing three words.
It's about asking:
What should my system do when two parts of it can no longer communicate?
Interview-ready answer ->
CAP theorem states that in a distributed system, when a network partition occurs between nodes, we cannot guarantee both strong Consistency and Availability at the same time.
Consistency means every request gets the latest, correct data.
Availability means every request receives a response.
Partition Tolerance means the system continues operating even when nodes cannot communicate with each other.
Since network partitions are inevitable in distributed systems, the practical trade-off is usually between Consistency and Availability during a partition — resulting in CP or AP systems.
Resources I used
While learning this topic, these were particularly useful:
A Plain English Introduction to CAP Theorem — Kaushik Sathupadi

Top comments (0)