CAP Theorem in Blockchain
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.
CAP Theorem or Brewer’s theorem states that it is feasible to provide either
consistency or availability—but not both—in the event of a network failure on a
distributed database, a theory from theoretical computer science about
distributed data stores. In other words, according to the CAP theorem, a
distributed database system that experiences a partition must choose between
Consistency and Availability.
We must simultaneously communicate over the network and store data among
several nodes in a distributed system. A distributed system frequently falls victim
to network failures because of its reliance on network calls in a significant way.
Tolerance for partitions is crucial. In this situation, we must decide, based on our
needs, whether to prioritize consistency or availability.
With blockchain technology, immediate consistency is frequently sacrificed for
availability and partition tolerance. By requiring a specific amount of
“confirmations,” blockchain consensus techniques are simply simplified to
eventual consistency.
Network failures can affect any distributed system, hence network partitioning
is usually required. There are just two choices remaining in the event of a
partition: consistency or availability. The system will return an error or time out if
a specific piece of information cannot be guaranteed to be current owing to
network segmentation when consistency is chosen above availability. The system
will always process the query and attempt to return the most recent version of
the data even if it cannot ensure that it is up to date because of network
partitioning when availability is preferred over consistency.
Blockchain is a decentralized database that manages a shared ledger that
cannot be altered. Transactions are what make up the shared ledger. Consensus
techniques are used to record transactions inside the shared ledger. Sharing
distributed transactions naturally raises questions about the CAP theorem.
Consistency is sacrificed in Blockchain due to the priority given to Availability
and Partition Tolerance. In this case, Partition tolerance (P), Availability (A), and
Consistency (C) on the blockchain are not attained simultaneously; instead, they
are acquired over time.
3. Partition Tolerance
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)
When availability is preferred over consistency the system will always process
the query and attempt to return the most recent version of the data even if it
cannot ensure that it is up to date because of network partitioning.
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.