Quick Notes on What is CAP Theorem?

This article briefly talks about what is CAP theorem and provides appropriate examples. I have come across many candidates appearing for architect interview who failed to answer the question such as some of the following:

  • What is CAP theorem?
  • RDBMS system such as Oracle achieves which of the following two: Consistency, Availability, Partition Tolerance
  • NoSQL datastore such as HBase tends to achieve which of the following two: Consistency, Availability, Partition Tolerance

The article below addresses some of the above questions. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

Following points are discussed later in this article:

  • What is CAP theorem?
  • Some Examples of DB system vis-a-vis CAP Theorem
  • Which DB system to choose based on CAP requirements?
What is CAP theorem?

CAP theorem states that any database system can only attain two out of following states which is Consistency, Availability and Partition Tolerance. Following is brief definition of these three terms:

  • Consistency: Any changes to a particular record stored in database, in form of inserts, updates or deletes is seen as it is, by other users accessing that record at that particular time. If they don’t see the updated data, it is termed as eventual consistency.
  • Availability: The system continues to work and serve data inspite of node failures.
  • Partition Tolerance: The database system could be stored based on distributed architecture such as Hadoop (HDFS).

Following diagram depicts the above three terms:

CAP theorem - Consistency, Availability, Partition Tolerance

CAP theorem – Consistency, Availability, Partition Tolerance

Following are some of the URLs of pages where further details could be found:

Some Examples of DB system vis-a-vis CAP Theorum
  • RDBMS systems such as Oracle, MySQL etc supports consistency and availability.
  • NoSQL datastore such as HBase supports Consistency and Partition Tolerance.
  • NoSQL datastore such as Cassandra, CouchDB supports Availability and Partition Tolerance.
Which DB system to choose based on CAP requirements?
  • CP-based database system: When it is critical that all clients see a consistent view of the database, the users of one node will have to wait for any other nodes to come into agreement before being able to read or write to the database, availability takes a backseat to consistency and one may want to choose database such as HBase that supports CP (Consistency and Partition Tolerance)
  • AP-based database system: When there is a requirement that database remain available at all times, one could DB system which allows clients write data to one node of the database without waiting for other nodes to come into agreement. DB system then takes care of data reconciliation at a little later time. This is the state of eventual consistency. In applications which could sacrifice data consistency in return of huge performance, one could select databases such as CouchDB, Cassandra.

 

Ajitesh Kumar
Follow me
Latest posts by Ajitesh Kumar (see all)

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com
Posted in NoSQL, Software Engg.

Leave a Reply

Your email address will not be published. Required fields are marked *