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

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

3 hours ago

Building an OpenAI Chatbot with LangChain

Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…

1 day ago

How Indexing Works in LLM-Based RAG Applications

When building a Retrieval-Augmented Generation (RAG) application powered by Large Language Models (LLMs), which combine…

5 days ago

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

6 days ago

What are AI Agents? How do they work?

Artificial Intelligence (AI) agents have started becoming an integral part of our lives. Imagine asking…

3 weeks ago

Agentic AI Design Patterns Examples

In the ever-evolving landscape of agentic AI workflows and applications, understanding and leveraging design patterns…

4 weeks ago