Categories: NoSQLSoftware Engg

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

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

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. 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.

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

1 month ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

2 months ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

2 months ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

2 months ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

2 months ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

2 months ago