Skip to content

Instantly share code, notes, and snippets.

@aemloviji
Last active May 6, 2020 19:22
Show Gist options
  • Save aemloviji/6d514a7fa34f36e4500ba764d850ef6c to your computer and use it in GitHub Desktop.
Save aemloviji/6d514a7fa34f36e4500ba764d850ef6c to your computer and use it in GitHub Desktop.
CAP theorem.

CAP theorem NoSQL database types

NoSQL (non-relational) databases are ideal for distributed network applications. Unlike their vertically scalable SQL (relational) counterparts, NoSQL databases are horizontally scalable and distributed by design—they can rapidly scale across a growing network consisting of multiple interconnected nodes.

The ‘CAP’ in the CAP theorem, explained

Let’s take a detailed look at the three distributed system characteristics to which the CAP theorem refers.

Consistency Consistency means that all clients see the same data at the same time, no matter which node they connect to. For this to happen, whenever data is written to one node, it must be instantly forwarded or replicated to all the other nodes in the system before the write is deemed ‘successful.’

Availability Availability means that that any client making a request for data gets a response, even if one or more nodes are down. Another way to state this—all working nodes in the distributed system return a valid response for any request, without exception.

Partition tolerance A partition is a communications break within a distributed system—a lost or temporarily delayed connection between two nodes. Partition tolerance means that the cluster must continue to work despite any number of communication breakdowns between nodes in the system.

NoSQL databases are classified based on the two CAP characteristics they support:

  • CP database: A CP database delivers consistency and partition tolerance at the expense of availability. When a partition occurs between any two nodes, the system has to shut down the non-consistent node (i.e., make it unavailable) until the partition is resolved.
  • AP database: An AP database delivers availability and partition tolerance at the expense of consistency. When a partition occurs, all nodes remain available but those at the wrong end of a partition might return an older version of data than others. (When the partition is resolved, the AP databases typically resync the nodes to repair all inconsistencies in the system.)
  • CA database: A CA database delivers consistency and availability across all nodes. It can’t do this if there is a partition between any two nodes in the system, however, and therefore can’t deliver fault tolerance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment