CAP Theorem

Akhil SharmaAkhil Sharma
2 min read

What does CAP stand for?

C - Consistency

Consistency in Database means it goes from one consistent state to another, but in CAP, it means you get the latest written value as the response.

A - Availability

Availability - Every request receives a response without the guarantee of it being the most recent write. This takes consistency out of the equation, It doesn’t guarantee consistency. The returned value might be the latest one or not.

P - Partition tolerance

Partition Tolerance - Let’s say there is a network where several modules are interacting with each other and due to some glitch or a module crashing, the network gets partitioned into two parts where each part is not able to interact with the other.
Partition tolerance means that even with this virtual separation, your system continues to work.

Distributed Systems always have a risk of one module getting crashed and the system getting a logical separation. In that case, you have 2 options

  1. Choose availability which means the system will always give a non-error response but it might come at the cost of consistency because what if the read is going to one part of the system and write is going to another part of the system and both these parts are not able to interact with each other due to some fault.

  2. Choose consistency which means you are okay with your system being down for some time but you want to response to be correct and consistent.

What if you can guarantee that there is no network partitioning?

If you are not operating in a wide area, the chances of a network partition are almost zero, and in that case, you can obtain both consistency and availability.

Again, one caveat here is that even if you are running a single-node system, if that single node crashes then your whole system goes down which means 100% availability is not possible but you can minimize the downtime.

What CAP theorem is, in the presence of network partition you have to sacrifice either consistency or availability.

0
Subscribe to my newsletter

Read articles from Akhil Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akhil Sharma
Akhil Sharma