Lably
Skip to content

CAP theorem

Need to sacrifice consistency or availability in the presence of network partitions

  • 3 min read
  • 2 chapters

Related on Lably

Through ACID, Availability and Relational database

Consistency
Every read receives the most recent write or an error. Consistency means that all clients see the same data at the same time, no matter which node they connect to. For this to happen, whenever data is written to one node, it must be instantly forwarded or replicated to all the other nodes in the system before the write is deemed ‘successful’. Consistency as defined in the CAP theorem is quite different from the consistency guaranteed in ACID database transactions.
Availability
Every request received by a non-failing node in the system must result in a response, without the guarantee that it contains the most recent version of the data. This is the definition of availability in CAP theorem as defined by Gilbert and Lynch. Availability as defined in CAP theorem is different from high availability in software architecture.
Partition tolerance
The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.

When a network partition failure happens, it must be decided whether to do one of the following:

  • cancel the operation and thus decrease the availability but ensure consistency
  • proceed with the operation and thus provide availability but risk inconsistency. This does not necessarily mean that system is highly available to its users.

Thus, if there is a network partition, one has to choose between consistency or availability.

During times of normal operations, a data store covers all three.

Explanation

No distributed system is safe from network failures, thus network partitioning generally has to be tolerated. In the presence of a partition, one is then left with two options: consistency or availability. When choosing consistency over availability, the system will return an error or a time out if particular information cannot be guaranteed to be up to date due to network partitioning. When choosing availability over consistency, the system will always process the query and try to return the most recent available version of the information, even if it cannot guarantee it is up to date due to network partitioning.

In the absence of a network partition, both availability and consistency can be satisfied.

Database systems designed with traditional ACID guarantees in mind such as RDBMS choose consistency over availability, whereas systems designed around the BASE philosophy, common in the NoSQL movement for example, choose availability over consistency, but MongoDB and Redis resolve network partitions by maintaining consistency while compromising on availability. CouchDB, Cassandra, and ScyllaDB are examples of AP databases. There are no NoSQL databases one would classify as CA. Most modern distributed databases offer configuration options for both consistency and availability.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication