Open In App

CAP Theorem in Blockchain

CAP theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the three guarantees: Consistency, Availability, and Partition. The article focuses on discussing CAP Theorem in Blockchain in detail.

The following topics will be discussed here:



  1. What is Blockchain?
  2. What is CAP Theorem?
  3. History of the CAP theorem
  4. The CAP in CAP Theorem
  5. CAP theorem NoSQL database types
  6. CAP Theorem applied
  7. CAP Theorem Examples
  8. Why does Blockchain Violate CAP Theorem?
  9. What is PACELC Theorem?

What is Blockchain?

Blockchain is a method of storing data that makes it challenging or impossible to alter, hack, or defraud the system. A hash, a sort of immutable cryptographic signature, is used to record transactions on a blockchain, a type of DLT.

What is the CAP Theorem in Blockchain?

CAP Theorem stands for Consistency, Availability, and Partition Tolerance. According to the theory, a distributed system cannot always ensure consistency, availability, and partition tolerance. When things go wrong, we must prioritize at most two distributed system features and trade-offs between them. 



History of CAP Theorem

CAP Theorem in Blockchain

As we know that CAP stands for Consistency, Availability, and Partition Tolerance so, let us understand Consistency, Availability, and Partition Tolerance with the help of some examples. Let us first understand availability as then it will be much easier to understand consistency and partition tolerance then.

1. Availability

Availability means that all clients who request data receive a response even if one or more nodes are down. In a distributed system, every operational node replies to each valid request made to it, to put it another way. 

Example: Imagine you are the customer of a well-known vehicle company in your city because of the incredible deals and services it provides. In addition, they provide fantastic customer service, so you can contact them whenever you have questions or issues and get answers right away. The car company is able to connect every consumer who phones to one of its customer service representatives. Any information needed by the customer regarding his cars, such as the service date, the insurance plan, or other details, can be obtained. Because any customer can connect to the business or its operator and obtain information about the user or client, we refer to this as availability.

2. Consistency

Consistency means that the duplicated data item will appear in the same copies on all nodes during different transactions. an assurance that each node in a distributed cluster returns the same, most recent, and successful writer. Every client’s perception of the data must be consistent to be considered consistent.  Sequential consistency, which is a particularly powerful type of consistency, is referred to as consistency in CAP. 

Example: Recently the insurance policy of your car got outdated and you want to update or get a new insurance policy for your car. You decide to call the bank or the insurance company and update it with them. When you call, you connect with an agent. This agent asks you for the relevant details of your previous policy. But once you have put down the phone, you realize that you missed one detail. So you frantically call the agent again. But, this time when you call, you connect with a different agent but then also, they are able to access your records as well and know that you are registering for your new insurance policy. They make the relevant changes in the house number and the rest of the address is the same as the one you told the last operator. We call this Consistency because even though you connect to a different customer care operator, they were able to retrieve the same information.

3. Partition Tolerance

A communication breakdown—a momentary delay or lost connection between nodes—is referred to as a partition in a distributed system. Partition tolerance describes the ability of a cluster to function even in the face of numerous communication failures between system nodes. 

Example: Unfortunately, you need to sell your car because it’s old and outdated and you don’t use it very often. So you list all of the specifics about your automobile on a website for sale, and then you get in touch with a buyer. He starts negotiating because he wants to acquire your car and hence wants to complete the agreement process. However, because the bargaining was not mutual, neither of you could sign the agreement. Therefore, we might conclude that the agreement has been breached or that there is no partition tolerance in this situation.

CAP Theorem NoSQL Database Types

 

Consistency and high availability are not compatible with NoSQL. Eric Brewer initially stated this in his CAP Theorem. We can only accomplish two out of the three guarantees for a database, consistency, availability, and partition tolerance. It is crucial to comprehend the NoSQL database’s constraints. Consistency and high availability are not compatible with NoSQL. 

It can be observed from the above diagram that Consistency and Availability are connected by a database CA, Availability and Partition Tolerance by a database AP, and Consistency and Partition Tolerance by a database CP. Let us discuss what CA, AP, and CP mean.

CA: CA database provides availability and consistency among all the nodes. However, it cannot accomplish this if there is a partition between any two system nodes, hence it is unable to provide fault tolerance. For eg: Applications used in banking and finance demand available and consistent data.

AP: AP database means that the system continues to operate even in the presence of node failures. AP-based systems compromise consistency and availability. Non- distributed databases like PostgreSQL uses AP-based database systems.

CP: CP database means that the system continues to operate even though network failures are occurring in the database. CP systems are strongly consistent but they are not properly available.

CAP Theorem Applied

1. Availability over consistency (A+P)

The following picture clearly shows Availability over Consistency:

 

2. Consistency over availability (C+P)

The following picture clearly shows Consistency over Availability:

 

CAP Theorem Examples

Example 1: A mobile phone has been designed in such a way that it has space for only one sim card which means no sharing.
Solution: This system guarantees Consistency, Availability, and Tolerance to Partitions.

Example 2: Immediately after sending a message to someone, that individual might not get it.
Solution: With this system, availability and partition tolerance are compromised without compromising consistency, or AP.

Example 3: When we build a form for a group of individuals, the others can only access it once we provide them permission to do so.
Solution: CP, or Consistency and Partition Tolerance without Compromising Availability, is ensured by this system.

The different database of CAP Theorem fits in different software:

Why does Blockchain Violate CAP Theorem?

What is PACELC Theorem?


Article Tags :