In this article, we will look at the basics of CAP Theorem.
CAP stands for Consistency, Availability, Partition Tolerance. It’s also called Brewer’s theorem and at best only 2 will be followed & 1 will be sacrificed.
Let’s take a look the details below
Consistency:
- Every read fetches the last write
User should be able to see the same data irrespective of which nodes they connect to on the system. Also, this data is the most recently written to the system. When write happens on a node in distributed system so that it’s replicated on all nodes so that user can see the same information from all nodes. This is what is referred as consistency.
Ex. When user updates the address information of AADHAR application, irrespective of whether he calls the customer service or login into AADHAR app he should see the same information.
Availability:
- Every read and write always succeed
User able to access the data at all times and every transaction that they do always succeed meaning it should return a response even if its failure.
Let’s assume that user calls the call center1 for modification in AADHAR app and ask for the latest updates made in his records & obtain the information. Second day, user calls the call center2 & information is available to him as well. This means data availability.
Partition Tolerance:
- System will continue to function when network partition occurs.
System will be able to work even if there is partition in the system. If node fails to communicate, then one of the replicas should be able to get the data to the user. This is called partition tolerance.
Three possible combination that are available are
- Availability and Partition Tolerance (AP)
Ex. Few databases which support AP are Cassandra, Couch DB, DynamoDB
- Consistency and Partition Tolerance (CP)
Ex. Few databases which support CP are HBase, MongoDB, Redis, MemcachedDB, Big Table
- Consistency and Availability (CA)
Ex. Few databases which support CA are PostgreSQL, MySQL
Hope this article was helpful.