Member-only story
The Basics — CAP Theorem Explained
CAP theorem or Brewers theorem (named after computer scientist Eric Brewer) often gets mentioned in combination with distributed systems.
The theorem states that it is impossible for a distributed system to have more than two of the following three properties:
- Consistency
- High Availability
- Partition tolerance
Distributed system is a collection of computers that are connected through a network and appear as a single computer.
What is consistency?
We have a cluster of four computers that are connected to each other and two operations that we can the cluster understands: read
and write
. The read
operation returns a value that is stored, and write
updates the stored value in the cluster.
In the current state of the cluster, all computers have a value called Hello
stored as shown in the figure below.
Let’s say we want to update the value from Hello
to Bye
and call the write
operation. We make the call to the cluster and the call ends up on computer 1 (top left) and the value gets updated as shown below.
As soon as that write operation happens, the value should get replicated to other computers in the cluster. However, if we try to read the value before the replication happens and the call ends up on computer 3 for example (bottom left), we will get back value Hello
. If that happens, we can say that the system is…