DEV Community

Cover image for CAP Theorm
Jayant
Jayant

Posted on

CAP Theorm

C - Consistency, Every Read receive most recent write or an error.
Consistency defined in CAP Theorm is quite different from Consistency in ACID DB Transaction


A - Availability, Every request received must give some response, the response returned will be the most recent data, but it can't gaurentee that data is upto to Date.


P - Partition Tolerance, The system continues to work, even if some nodes goes down.

It states that On Partition (network split, some nodes can't communicate others) you can either provide consistency or availability.

  • If we Choose Consistency - the system will return error or timeout if certain data can't be returned with a guarentee that it is upto date.
    • In a Banking system we prefer consistency over availability.
  • If we Choose Availability - the system will process the query and try to return the most recent data, however it is not guarenteed it is uptoDate.

    • In a Social Media Platform we prefer availability over consistency.

    CAP Theorm

CP - Consisteny when Partition occured.

AP - Availability when Partition occured.

CA - Consistency with Availability, this is assuming we will not encounter any partition, this could be true in the case of when there is single node. This can be true for the case where our nodes are nearby, maybe in the same room.

No, System has 100% availiability, software break easily but we can try to maximize the availability so that users don't face any outage.

In AP the system will get eventual consistent once the network heals.

Databases designed with traditional ACID property such as RDBMS choose consistency over availability, whereas system designed around BASE philosopy, common in NOSQL chooses availability over consistency.

The CAP theorm only true if we have large distributed system and when we have partition in network. with using superior hardware we can achieve both availability and consistency.

Some Examples of it - Spanner, cockroachDB

Top comments (0)