khan Waseem

Fri Jan 27 2023


2 min read

What is CAP theorem?

cap theorem

The CAP theorem, also known as Brewer’s theorem, is a fundamental principle in distributed systems and database design. It was formulated by computer scientist Eric Brewer in 2000 and states that in a distributed data store, you can prioritize at most two out of the following three guarantees:


This refers to ensuring that all nodes in a distributed system see the same data at the same time. In other words, when a write operation is performed, all subsequent read operations should return the updated data.

2. Availability:

Availability means that every request made to the system, whether it’s a read or a write request, receives a response, either success or failure, without any guarantees about the data being consistent across nodes.

3. Partition Tolerance:

Partition tolerance deals with the system’s ability to function and continue providing its services even in the presence of network partitions or communication failures between nodes. Partitions can occur due to network issues, hardware failures, or other reasons.

According to the CAP theorem, a distributed system can’t simultaneously achieve all three guarantees perfectly. In the case of a network partition (P), a system must choose between maintaining consistency (C) or ensuring availability (A). This leads to three possible scenarios:

1. CP Systems:

In scenarios where consistency is prioritized over availability, a system will maintain consistency even in the face of network partitions. This may result in the unavailability of certain nodes or services during network disruptions.

2. CA Systems:

 If both consistency and availability are critical, a system might choose to forgo partition tolerance and become unavailable in the presence of network partitions in order to ensure consistency and availability when the network is stable.

3. AP Systems:

Systems that prioritize availability over strict consistency will sacrifice perfect consistency in favor of remaining operational during network partitions. This can result in temporary inconsistencies between nodes.

The CAP theorem highlights the trade-offs that developers and architects need to consider when designing distributed systems. Different use cases and applications may require different choices depending on the specific requirements and constraints. It’s important to understand that the CAP theorem doesn’t dictate a specific choice for every scenario but rather helps guide decisions in distributed system design.