top of page
Programming

What is the CAP theorem? Is the CAP theorem still valid?

Dec 12, 2022
4 min read

Updated: Feb 14, 2023

You can listen to the audio of this blog here


Let's dive right in -


What is the CAP theorem?

CAP theorem (also known as Brewer’s theorem) is a theory that was formulated by Eric Brewer in 2000. The CAP theorem states that a distributed database system cannot simultaneously provide consistency, availability, and partition tolerance. A distributed database system can only guarantee 2 out of these 3 principles.


Consistency

Consistency implies that the data stored across all the databases and storage units are the same. This means that if I were to read from any of the data sources, I would get the latest and updated information. A system that follows this principle is called a consistent system.


Availability

Availability indicates that the system should be available 100% of the time. There should be no downtime in the system and no request should throw an exception or an error. It is important to note that an available system can still return a result that is not the latest version of the data.


Partition Tolerance

Partition refers to the situation when the channel of communication between two connected systems is broken in a distributed system architecture. Partition Tolerance means that the system will continue to work even if there is a partition and a few messages are dropped or there is a delay in message communications across each system.



Where is the CAP theorem used in the real world?

In real-world scenarios, "Partition Tolerance" is a property that cannot be avoided as most of the real-world scenarios use a distributed data storage unit and are bound to have partitions, so you would want your system to be tolerant to such message outages.


Now we are left to choose between Consistency and Availability. Yes, as per the CAP theorem we can choose among these two combinations:

  • CP (Consistency and Partition Tolerance)

  • AP (Availability and Partition Tolerance)


As you start to scale, the problems of consistency and availability start becoming a problem as partitioning data sources become a necessity.


If you want to know more about System Scaling, check out this blog on Horizontal vs Vertical Scaling: https://www.thegeekyminds.com/post/all-about-scaling-a-system-horizontal-scaling-vs-vertical-scaling-system-design

If a NoSQL database is partitioned, it can either be CP (Consistency and Partition Tolerance) or AP (Availability and Partition Tolerance). If a NoSQL database is CA (Consistency and Availability), it means it has not been partitioned and is monolithic.


CP (Consistency and Partition Tolerance) with NoSQL


MongoDB is an example of a NoSQL database that follows CP (Consistency and Partition Tolerance). MongoDB stores data in several nodes. Every few seconds the primary node sends a heartbeat ping to the other nodes to check that it is alive. If any node does not respond to this signal, it is retired and cannot be accessed.

This way the NoSQL database compromises on availability to be consistent


AP (Availability and Partition Tolerance) with NoSQL


Cassandra is an example of a distributed database that uses AP (Availability and Partition Tolerance). Cassandra is a P2P (Peer to Peer) system that copies data on multiple nodes. The data which is returned is based on a "voting" method where the data in more nodes is assumed to be correct. This means that if a write operation was made recently and is present on only one of the nodes, the data returned would not be the latest as most of the nodes have an older copy of the data.

Cassandra however guarantees eventual consistency where the data is replicated to other nodes with time.


Is the CAP theorem valid in today's world?

Yes, of course, the CAP theorem is still valid and it is an important point to keep the trade-offs in mind while designing systems. Although we have come up with better solutions like eventual consistency, achieving all the parts of the "CAP" theorem simultaneously is still not possible.

The CAP theorem should be seen as a guiding tool while designing distributed systems as to which database to choose and how to design it.


The CAP theorem says that only 2 of the 3 principles can be achieved but designing systems in the real world need not be so black and white. You can opt for solutions that provide eventual consistency or eventual availability. By this even though you can't fully achieve all the 3 principles simultaneously but it is a better version of having only one of them (Consistency and availability).


So do not take the CAP theorem as an absolute, but think of it as something where there can be partial trade-offs. Be innovative while designing systems.


There's no one right answer when it comes to designing systems. As a software developer, it is your responsibility to look at business needs and implement whatever works best for your organization.


Blockchain technology is an excellent example where it sacrifices immediate consistency over eventual consistency.



A Brief History of the CAP Theorem

After the invention of the transistor, computer architects needed to figure out how to increase data storage in a reliable way. One solution was to use a distributed system. This is when the CAP theorem was first introduced by Eric Brewer of UC Berkeley.


Brewer's paper on the CAP theorem became popular after it was published in 2000, and his ideas were quickly adopted by architects who were looking for ways to solve their problems with data storage.


Bonus: CAP Theorem and Latency


Many people say that the CAP theorem does not take into consideration the aspect of latency. But actually, partition and latency are deeply connected. When we say partition, it does not necessarily mean a breakage of communication between 2 interconnected systems, it also means that the message was not delivered in a given time frame, which is basically a timeout.


CAP theorem is as valid as it was in the 2000s when it was developed. It is just that the dynamics and trade-offs have changed as we have advanced a lot in terms of system design and technology.


And that's a wrap! Hi, I am Gourav Dhar, a software developer and I write blogs on Backend Development and System Design. Subscribe to my Newsletter and learn something new every week - https://thegeekyminds.com/subscribe




11 Comments


This is a very insightful article explaining the CAP theorem and its importance in designing reliable distributed systems. I particularly appreciate how the examples of MongoDB and Cassandra make the concepts easier to understand. The discussion of consistency, availability, and partition tolerance highlights the importance of making informed technical decisions as systems grow. Articles like this encourage curiosity, logical thinking, and problem-solving. International Schools in Nairobi can help learners build these important skills by promoting technology education, critical thinking, and an interest in computer science from an early age. Thank you for sharing this useful explanation!

Like

I found this article very helpful because it explains the CAP theorem in a clear and practical way. I particularly appreciate how the examples of MongoDB and Cassandra demonstrate the trade-offs between consistency, availability, and partition tolerance in distributed systems. Buy cars in Kenya from Ace Prestige Motors today! As technology continues to evolve, I believe understanding these principles is essential for developers who want to build reliable and scalable applications. I also like the reminder that system design involves balancing technical requirements with business needs rather than looking for one perfect solution. This article provides a useful foundation for anyone learning about databases and distributed system architecture.

Like

This is genuinely one of the clearest explanations of the CAP theorem I’ve come across. A lot of tutorials get bogged down in overly dense academic jargon, but breaking down how distributed systems must choose between Consistency, Availability, and Partition Tolerance—especially emphasizing that network partitions are an unavoidable physical reality you have to design around—makes the core architectural trade-offs so much easier to visualize.

The distinction contrasting CP databases (like HBase or MongoDB prioritizing strict consistency during a network split) with AP systems (like Cassandra or DynamoDB favoring high availability and eventual consistency) really helps ground the theory in real-world cloud engineering choices.

Trying to master these database design patterns alongside consensus algorithms like Paxos and Raft while managing a…

Like

Great explanation of the CAP theorem! The real-world examples of MongoDB and Cassandra make it easier to understand the trade-offs between consistency and availability in distributed systems. Balancing technical concepts with practical applications is especially helpful for students learning system design. For learners managing demanding coursework alongside other responsibilities, finding the right academic support can also make a difference. Some students may search for options to pay someone to take my online class, but understanding the concepts and developing practical skills should remain a priority. Thanks for sharing this informative guide!

Like

This is a clear and practical introduction to the CAP theorem. I especially liked how the post breaks down consistency, availability, and partition tolerance before connecting them to real-world distributed databases. The examples of MongoDB and Cassandra make the discussion easier to understand because they show how different systems can make different trade-offs. Cars for sale in Nairobi Kenya are affordable at Magari Deals.

The point about partition tolerance being difficult to avoid in distributed systems is also important. As systems grow and data is spread across multiple nodes, developers have to think carefully about what matters most for a particular application. The discussion of CP and AP systems gives a useful starting point for understanding these design choices.

I…

Like
download (7)_edited.png
Subscribe to my Youtube Channel @codewithgd

Related Articles

Videos you might like

Let's Get
Social

  • alt.text.label.Twitter
  • alt.text.label.LinkedIn
  • 25231
Subscribe to our NewsLetter

Join our mailing list to get a notification whenever a new blog is published. Don't worry we will not spam you.

bottom of page