DEV Community

Rossano D'Angelo
Rossano D'Angelo

Posted on

CAP Theorem: Consistency, Availability, Partition tolerance

This theorem states that it is impossible for a distributed system to simultaneously provide more than two of these three guarantees:

  • Consistency: all clients see the same data at the same time no matter which "node" of the system they connect to

  • Availability: any client which requests data gets a response even if some of the "nodes" of the system are not available

  • Partition tolerance: the system continues to operate despite network partitions1

CAP Theorem explained

Ideal situation

In an ideal world, network partition never occurs

CAP Theorem Ideal World

Real world distributed system

In a distributed system, data is usually replicated multiple times because partitions cannot be avoided.
In the example below, node n3 becomes unavailable and cannot communicate with nodes n1 or n2. Also data cannot be propagated to n3 from n1 or n2.

CAP Theorem Real world

If we choose consistency over availability (CP system) we must block all write operations to nodes n1 and n2 to avoid data inconsistency among these three nodes, and this makes the system unavailable.

However, if we choose availability over consistency (AP system) the system remains available and accepts read operations, even though it might return stale data. For write operations, nodes n1 and n2 will keep accepting them and data will be synced to node n3 when the network partition is resolved.


  1. a partition indicates a communication break between two "nodes" 

Top comments (0)