CAP Theorem

Distributed Systems

February 01, 2021

CAP theorem is a fundamental theorem in distributed systems. It states that a distributed data store or any distributed system with a state can have at most two of the following three properties.

A lot of terms. But the definition mentioned above is not complete. Let’s break it down and understand step by step.

Distributed Systems

A distributed system contains multiple nodes which are physically separate but linked together by the network. All nodes communicate with each other and together form a distributed system.

A single node cannot be called a distributed system. It has to be definitely more than one node.

Now let’s go over what it is meant by the system to be consistent, available, and partition tolerant.

Consistency

Every read must receive the most recent write or an error. It means every read operation that begins after a write must receive that write value.

If not, it is said to be an inconsistent system.

Let’s assume there are two servers S1, S2, and Client C. Initially S1 and S2 have values v0 with them. Now, the Client sends a write request with value v1 to S1.

The S1 sends out an acknowledgment to the client only after all nodes are updated.

After that client sends a read request to S2. If the value returned by S2 is v1, the distributed system is consistent. As all the nodes are updated with the most recent write.

This is the expected functionality of a consistent system.

In case of an inconsistent system, the server S1 sends out the acknowledgment after it is updated and the client may not receive the most recent write when it queries S2.

Availability

Every non-failing node returns a response for all read and write requests in a reasonable amount of time without the guarantee that it contains the most recent write.

Here, the server is not allowed to ignore the requests. If it is not crashed, it must eventually respond to the client.

Partition Tolerance

The system continues to operate despite an arbitrary number of messages being dropped by the network between nodes.

It means our system should function correctly despite the network partitions.

What is a network partition?

Below pictures without and with partition answers that.

Network Partition
Network Partition

Note: The consistency in ACID Properties represents a different concept than the consistency in the CAP theorem.

Understanding the CAP Theorem

The CAP Theorem states that in a distributed system, it's impossible to simultaneously achieve all three of the following guarantees:

Implications of the CAP Theorem

Scenario: Choosing Availability over Consistency

When choosing availability over consistency in the presence of a network partition:

Scenario: Choosing Consistency over Availability

When opting for consistency over availability:

Gilbert and Lynch's Proof

Gilbert and Lynch demonstrated that a distributed system cannot achieve all three properties simultaneously:

Thus, Gilbert and Lynch's proof underscores that any system claiming to be consistent, available, and partition-tolerant ultimately fails to maintain consistency during network partitions.

Resources

Article Assistant

Ask questions about this article and get instant AI-powered answers.

AI-generated content may contain inaccuracies. Verify critical information.