CAP Theorem

CAP Theorem

A distributed system can not provide all guarantees.

Play this article

This article is the third one of my Distributed Systems series, the previous one can be found here: Sharding.

CAP Theorem

Screenshot from 2022-09-02 16-50-24.png

We gonna go over all three terms: Consistency, Availability and Partition Tolerance.

CAP Theorem states that only 2 of these three guarantees can be guaranteed in a distributed system, not all three at the same time.


Whatever I read from the database, I'll always see what I have most recently written.


When I read from the database, I always get a value returned. When I write to the database, I can write.

Partition Tolerance

In a distributed system, there will be cases where parts of the database won't be able to communicate with other parts of the database. When this happens, the database should be able to deal with things till the partition is healed.


P is something we must have because some parts of the database will be cut off from others. We should design the nodes to fail independently, and not cause the whole system to fail. The system should be fault tolerant.

We can only guarantee, either consistency or availability.

You should look at the system you're building and see which pros outweigh the others.