ArticleslgStudy

mathematics

CAP theorem

CAP theorem is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand CAP theorem rather than just read about it. In short: In database theory, the CAP theorem, also named Brewer's theorem after computer scientist Eric Brewer, states that any distributed data store can provide at most two of the following three guarantees: Consistency Every read receives the most recent write or an error. Consistency means that all clients see the same data at the same time, no matter which node they connect to.

CAP theorem — main illustration
CAP theorem — illustration

Key takeaways

  • CAP theorem belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect CAP theorem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of CAP theorem from memory before moving on to harder problems.

Reference excerpt

In database theory, the CAP theorem, also named Brewer's theorem after computer scientist Eric Brewer, states that any distributed data store can provide at most two of the following three guarantees:

Consistency Every read receives the most recent write or an error. 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’. Consistency as defined in the CAP theorem is quite different from the consistency guaranteed in ACID database transactions. Availability Every request received by a non-failing node in the system must result in a response, without the guarantee that it contains the most recent version of the data. This is the definition of availability in CAP theorem as defined by Gilbert and Lynch. Availability as defined in CAP theorem is different from high availability in software architecture. Partition tolerance The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes. When a network partition failure happens, it must be decided whether to do one of the following:

cancel the operation and thus decrease the availability but ensure consistency proceed with the operation and thus provide availability but risk inconsistency. This does not necessarily mean that system is highly available to its users.

Thus, if there is a network partition, one has to choose between consistency or availability. During times of normal operations, a data store covers all three.

Explanation No distributed system is safe from network failures, thus network partitioning generally has to be tolerated. In the presence of a partition, one is then left with two options: consistency or availability. When choosing consistency over availability, the system will return an error or a time out if particular information cannot be guaranteed to be up to date due to network partitioning. When choosing availability over consistency, the system will always process the query and try to return the most recent available version of the information, even if it cannot guarantee it is up to date due to network partitioning. In the absence of a network partition, both availability and consistency can be satisfied. Database systems designed with traditional ACID guarantees in mind such as RDBMS choose consistency over availability, whereas systems designed around the BASE philosophy, common in the NoSQL movement for example, choose availability over consistency, but MongoDB and Redis resolve network partitions by maintaining consistency while compromising on availability. CouchDB, Cassandra, and ScyllaDB are examples of AP databases. There are no NoSQL databases one would classify as CA. Most modern distributed databases offer configuration options for both consistency and availability.

History According to computer scientist Eric Brewer of the University of California, Berkeley, the theorem first appeared in autumn 1998. It was published as the CAP principle in 1999 and presented as a conjecture by Brewer at the 2000 Symposium on Principles of Distributed Computing (PODC). In 2002, Seth Gilbert and Nancy Lynch of MIT published a formal proof of Brewer's conjecture, elevating it to a theorem. In 2012, Brewer clarified some of his positions, including why the often-used "two out of three" concept can be somewhat misleading because system designers only need to sacrifice consistency or availability in the presence of partitions; partition management and recovery techniques exist. Brewer also noted the different definition of consistency used in the CAP theorem relative to the definition used in ACID. A similar theorem stating the trade-off between consistency and availability in distributed systems had been published by Birman and Friedman in 1996. Birman and Friedman's result had restricted this lower bound to non-commuting operations. The PACELC theorem, introduced in 2010, builds on CAP by stating that even in the absence of partitioning, there is another trade-off between latency and consistency. PACELC means, if partition (P) happens, the trade-off is between availability (A) and consistency (C); Else (E), the trade-off is between latency (L) and consistency (C). Some experts like Marc Brooker argue that the CAP theorem is particularly relevant in intermittently connected environments, such as those related to the Internet of Things (IoT) and mobile applications. In these contexts, devices may become partitioned due to challenging physical conditions, such as power outages or when entering confined spaces like elevators. For distributed systems, such as cloud applications, it is more appropriate to use the PACELC theorem, which is more comprehensive and considers trade-offs such as latency and consistency even in the absence of network partitions.

See also Fallacies of distributed computing Lambda architecture PACELC theorem Paxos (computer science) Raft (computer science) Zooko's triangle Inconsistent triad Trilemma

References

Illustrations

CAP theorem: CAP theorem Euler diagram
CAP theorem Euler diagram

Worked examples

Example 1 — a first encounter with CAP theorem

Start with the simplest possible case. Write down what CAP theorem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to CAP theorem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about CAP theorem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of CAP theorem

In research
CAP theorem appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses CAP theorem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
CAP theorem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database management systems, Distributed computing, so understanding it makes those chapters shorter.
In everyday life
Look for CAP theorem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “CAP theorem” →

How to study CAP theorem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what CAP theorem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain CAP theorem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is CAP theorem in simple terms?

In database theory, the CAP theorem, also named Brewer's theorem after computer scientist Eric Brewer, states that any distributed data store can provide at most two of the following three guarantees: Consistency Every read receives the most recent write or an error. Consistency means that all clie…

Why does CAP theorem matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study CAP theorem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on CAP theorem.

Tags

  • Database management systems
  • Distributed computing

Keep exploring