CAP Theorem states that a distributed system can deliver only two of three desired characteristics: Consistency, Availability, and Partition tolerance. In this article I’ll explore what CAP theorem is and how it relates to blockchain technology.
What is CAP Theorem
CAP theorem, was introduced by Eric Brewer in 1998 and proven as a theorem in 2002. It states that a distributed system cannot simultaneously achieve Consistency, Availability, and Partition tolerance.
- Consistency means that all nodes in the system have the same copy of data.
- Availability means that all nodes are up, accessible, and accepting incoming requests.
- Partition tolerance means that the system continues to operate correctly even if a group of nodes is unable to communicate with other nodes due to network failures.
In the Venn diagram above, we see that only two properties at a time can be achieved: either AP, CA, or CP.
- If we opt for CP (consistency and partition tolerance), we sacrifice availability.
- If we opt for AP (availability and partition tolerance), we sacrifice consistency.
- If we opt for AC (availability and consistency), we sacrifice partition tolerance. However, AC does not exist in practice.
CAP Theorem In Practice
To illustrate the concept of the CAP theorem, let’s consider a distributed system with only two nodes. Consistency is achieved when both nodes have the same up-to-date copy of the data. Availability is achieved when both nodes are up and running and responding with the latest copy of data. Partition tolerance is achieved when the network continues to operate despite communication failure or delay between nodes.
However, in the event of a partition, either availability or consistency is unachievable. In blockchains, consistency is sacrificed in favour of availability and partition tolerance, achieving eventual consistency over time through validation from multiple nodes.
If you’ve looked at Ethereum’s nodes since the merge you may have seen reorgs take place when nodes argue out which blocks to follow. This is an example of the work arounds in place to mitigate the sacrifice of consistency within blockchain systems.
The Blockchain Trilemma
The blockchain trilemma is a concept that was likely derived from CAP Theorem which highlights the trade-offs that exist between three desirable properties of a blockchain system: scalability, security, and decentralisation.
Scalability refers to the ability of the blockchain system to handle a large volume of transactions efficiently. As more users join the network and the number of transactions increases, the blockchain must be able to keep up with the demand without sacrificing its other properties.
Security refers to the level of protection that the blockchain system provides against various types of attacks, such as double-spending, 51% attacks, and others. The security of the system is critical, as any weakness or vulnerability can lead to financial losses for users and damage the overall trust in the blockchain.
Decentralisation refers to the distribution of power and control among the network participants. In a decentralised blockchain system, no single entity has complete control over the network. This helps to ensure the transparency and immutability of the blockchain, as well as prevent censorship and protect user privacy.
Like CAP Theorem the Blockchain Trilemma states that it is impossible for a blockchain system to simultaneously achieve all three properties at the same time. This is because each property places different demands on the system, and optimizing for one property requires sacrificing another.
For example, increasing the block size or reducing the block time can improve scalability by allowing more transactions to be processed, but it can also reduce security by making the system more vulnerable to attacks. Similarly, increasing the number of nodes and their participation in consensus can improve decentralisation, but it can also reduce scalability by slowing down the consensus process.
The trilemma is a challenge for layer 1 blockchain developers who must carefully balance the trade-offs between scalability, security, and decentralisation when designing a blockchain system.
Scaling Compromises
Different blockchain projects have taken different approaches to this challenge making compromises to meet the principles of their developers and users.
Bitcoin achieves the highest levels of decentralization and censorship resistance at the cost of scalability and high electrical consumption costs. This could potentially cause security issues in the future if declining block rewards can not incentivise a large enough network to prevent a 51% attack.
Ethereum is rolling out upgrades that prioritise scalability at the cost of decentralization and security. Many alternate layer 1 and layer 2 blockchains run centralized sequencers and consensus modules completely compromising on decentralization for the benefit of scalability and security.
The Blockchain Trilemma states that there is no “magical solution” which is important to remember when a new blockchain launches with a trillion transactions per second. By understanding the first principles of blockchain technology we can make more informed assessments of emerging technologies in the space and invest accordingly.