Vai al contenuto

CAP Theorem: explanations and examples

  • di

What does the CAP theorem say?

With this article, I want to give you a quick introduction to the CAP theorem, also known as Brewer’s Theorem (after the name of the originator), which, in summary, argues that it is not possible for a distributed datastore to simultaneously provide the following three guarantees: consistency (C), continuous availability (A) and partition tolerance (P). The CAP theorem tells us that: in a distributed computer system it is not possible to provide, or better yet, ensure more than two of the following three conditions simultaneously, it is therefore, necessary to sacrifice one of the three from time to time.

The definitions of the three guarantees are briefly described below.

  • Consistency (consistency): all clients see the same data at the same time.
  • Availability (availability): all clients can perform read and write operations at any time and receive a response from the system.
  • Partition Tolerance: the system continues to function as a whole even when there are no nodes or when individual nodes can no longer communicate with each other.

The CAP theorem is often used to represent the architecture orientation of a distributed system or framework of which there can be 3 types, the following are some examples of frameworks classified according to the CAP theorem:

  • Consistency/Availability: high consistency/high availability. This is the trade-off typically offered by RDBMS such as MySQL, PostgreSQL, MariaDB.
  • Consistency/Partition tolerance: high consistency/partition tolerance. This tradeoff is the one preferred by solutions such as MongoDB Sharded, HBase, BigTable, Redis.
  • Availability/Partition tolerance: continuous availability/partition tolerance. This tradeoff is offered by solutions such as MongoDB in ReplicaSet, Apache Cassandra, CouchDB, DynamoDB and Riak

Now that you are clear on what the CAP theorem says, I leave you with a question, which of the above 3 case histories do you think the HDFS framework falls into? let me know in the comments! 🙂

References

[1] Julian Browne, “Brewer’s CAP Theorem – The kool aid Amazon and Ebay have been drinking.”
http://www.julianbrowne.com/article/viewer/brewers-cap-theorem

[2] Wikipedia, “CAP Theorem.”
https://it.wikipedia.org/wiki/Teorema_CAP Translated with www.DeepL.com/Translator (free version)