Posted in Notes, Reading Challenge, SWE Notes

CAP & PACELC Theorem

Blogs read:

  1. https://shekhargulati.com/2018/08/08/week-2-cap-theorem-for-application-developers/
  2. https://dzone.com/articles/understanding-the-cap-theorem
  3. https://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html
  4. https://bardoloi.com/blog/2017/03/06/pacelc-theorem/
  5. http://dbmsmusings.blogspot.com/2010/04/problems-with-cap-and-yahoos-little.html

My Notes:

CAP -> Consistency, Availability, Partition Tolerance

The theorem says that in the event of a Partition failure, a system can either be consistent or it can be available. An important point to note here is that this is the case ONLY if there is a partition failure (network failure). If there isn’t, the system can absolutely be BOTH consistent AND available.

  1. Consistency is when a write fails if there is a partition failure. This way, all the nodes remain consistent and you get the latest write available.
  2. Availability is when a write happens successfully, and it’s okay if some of the nodes get the latest write and others don’t. The end result would be that you don’t get consistent response depending on which node you hit, but you’ll at least get some data.
  3. Partition tolerance is ability of a system to continue to work in the event of a network failure among several distributed nodes.

Since during Network partition, some communication among nodes is broken, you can only opt for either getting uniform data from all nodes, or always some data from the nodes.

How to implement a Consistent System:

  1. If one node is failing and the other is not, fail all writes and reads on one node, and continue accept read and writes on the other node. This way, the node that can’t have updated data will not be showing stale data.
  2. The other option is to allow only reads on all systems and fail all writes. This way the “view” of the data requested from all nodes will be consistent.

Databases can’t be considered outrightly as a CP or AP system. Most databases are configurable.

PACELC -> Partition, Availability, or Consistency, Else, Latency or Consistency

This is the extension of the CAP theorem.

In case of a partition, you have to choose between Availability or Consistency, but if there is no partition failure, then you’ll have to further choose between latency and consistency.

Leaving this out here for your review:

Source: wikipedia

Leave a comment