The CAP theorem states that a distributed database can fulfil at most two out of three guarantees, that is, Consistency, Availability and Partition Tolerance.

Since it is not possible to fulfil all three requirements, a combination of two must be chosen for deciding what technology to use. Based on such combinations, RDBMS and NoSQL databases can be compared as follows:

  • RDBMSs provide availability and consistency. A traditional RDBMS is a single-node system. Therefore, there is no network partitioning.
  • NoSQL databases store data in a distributed manner across a cluster of interconnected machines and provide network partitioning tolerance. So, in the case of network partitioning, one has to make a trade-off between consistency or availability. Hence, there are two types of NoSQL databases that fulfil two different sets of guarantees:
  • Consistency and Partition Tolerance (CP)
  • Availability and Partition Tolerance (AP)

Depending upon the type of application, while designing a networked shared-data system, system designers should make a trade-off between consistency and availability.

Proof of CAP Theorem

Assumption: The distributed data store satisfies all three requirements: consistency, availability and partition tolerance.

Consider a system with two nodes G1 and G2. Both these nodes have an object, Object-0, whose initial value is V0. The nodes can communicate with each other and with the client.

Proof of CAP

Now, suppose the network between the two nodes gets partitioned; the two nodes G1 and G2 can no longer communicate with each other.

Proof of CAP

A client C1 wants to overwrite the value of object-0 in node G1. Now, since the system is available, the client is able to change the value of Object-0 to V1 in node G1.

Proof of CAP

Since the network is partitioned, the value of Object-0 is not updated in node G2. Now, a read request has been raised for Object-0. Since the system is available, the client gets a response to the request. Assume node G2 responds to this request by returning its older value, V0, thereby contradicting the consistency assumption.

Proof of CAP

Therefore, when a network partition occurs, one has to choose between consistency and availability.

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer