AI Glossary / Data engineering and architecture / Intermediate
CAP theorem
Definition
The CAP theorem identifies a limit of distributed shared-data systems: when communication between parts of the system can fail, a service cannot guarantee both linearizable consistency and completion of every request to a non-failing node. CAP stands for consistency, availability and partition tolerance.
What it means
Consistency here means a strong, specific property: operations behave as though they act on one logical copy, in an order that respects completed operations in real time. It is not simply the general idea that data is accurate, nor the same definition as consistency in ACID transactions.
Availability in the formal result concerns requests eventually completing; it is not a monthly uptime percentage or a promise about a particular response-time target. Partition tolerance means considering executions in which communication between groups of nodes fails.
The familiar phrase “choose any two” can mislead. A distributed service cannot make network failure impossible by declining a product feature. The useful design question is what operations can complete, with what guarantees, when communication is unavailable and during recovery.
How it works
Suppose replicas on opposite sides of a network partition can each receive client requests but cannot exchange information. A write accepted on one side cannot necessarily be known on the other. The isolated side cannot always distinguish a world in which the write happened from one in which it did not.
If it must answer every read, it can return a value that violates the required single-copy ordering. If it waits for information that may never arrive, it cannot guarantee completion. No faster processor or more elaborate guessing algorithm removes the missing information.
Real systems choose specific behavior for different operations and data. Some delay or reject operations that require coordination, while others allow useful local work under weaker guarantees. Recovery then needs an explicit plan. CAP describes an impossibility boundary; it does not prescribe a complete database architecture.
Three practical examples
- A replicated configuration service pauses certain updates when it cannot obtain the coordination needed to preserve its consistency guarantee.
- A collaborative application accepts disconnected edits under defined merge rules instead of promising that every user immediately sees one latest state.
- A system-design review distinguishes the guarantees for reading a public catalog from those for confirming a unique reservation.
Think of it this way
Think of two offices maintaining a shared notice while their communication line is down. One office receives a change. The other cannot know about it merely by being required to answer visitors promptly.
The analogy shows an information limit, not a recommendation to stop all office activity. Each office may still perform tasks that do not require the missing information. Software designs similarly distinguish operations that need coordination from those that can safely proceed independently.
Worked example
Consider a fictional replicated status value, initially “draft” at nodes A and B. A network partition prevents communication between them. A client writes “approved” through A and receives confirmation that the write has completed. After that confirmation, another client reads the value through B.
If B immediately returns its stored “draft” value, the read does not satisfy the stated linearizable single-value contract: it follows a completed write but returns the older value. If B instead waits for A and the partition persists indefinitely, the read cannot be guaranteed to complete.
Returning an error may be a sensible operational choice, but it is not a successful read that fulfills the availability guarantee of this read/write service. Allowing a labeled, possibly stale read changes the service contract; it does not defeat the theorem. This example assumes no other communication path supplies the missing write.
Illustrative case study
Illustrative case study: A fictional training-event platform separates browsing an event description from confirming the last available seat. During a regional communication failure, designers permit a clearly bounded cached description to remain visible. Seat confirmation follows a coordination policy that may temporarily prevent confirmation from an isolated location.
The team tests recovery and ensures the interface does not present an unconfirmed request as a completed booking. It also evaluates an alternative design with capacity preallocated to regions, recognizing that this changes the coordination problem and available local actions.
This invented case illustrates operation-specific design. It claims no real platform outcome and does not assign a universal CAP label to every component or every possible reservation architecture.
Common misconceptions and mistakes
- Treating CAP as a rule that every system must permanently give up one useful property.
- Equating CAP consistency with all forms of data correctness or ACID consistency.
- Treating a quick error response as successful completion of the requested data operation.
- Assuming eventual consistency means immediate agreement or conflict-free recovery.
- Using a database's “CP” or “AP” label without examining its operation, configuration and failure assumptions.
Business use
For businesses, CAP helps turn vague resilience promises into explicit service behavior. Identify which decisions need coordinated state and what users should experience when that coordination is unavailable. Consider the business cost of stale information, delayed work and conflicting updates separately.
Test network separation and recovery, not only server crashes. Document which operations remain possible and how pending work is reconciled. For AI agents using distributed tools, a timeout or unavailable confirmation should remain an uncertain outcome until resolved; fluent language cannot establish that a remote state change safely completed.
People also ask
Does CAP mean a system cannot normally be both consistent and responsive?
No. The impossibility concerns guarantees under the stated communication-failure model, not a claim that normal operation must always sacrifice one.
Is partition tolerance the same as data partitioning or sharding?
No. Here partition means a communication failure that separates parts of the system.
Does CAP tell us which database to buy?
No. It provides a conceptual limit; workload, semantics, failure handling and operational requirements still need evaluation.
Check your understanding
B returns “draft” after A has confirmed the write “approved”, while they cannot communicate. Has the system preserved the stated linearizable read/write contract?
Answer: No. The later read returned an older value. Accepting that result requires a weaker contract or different application semantics.
Related terms
- Availability
- Replication (statistics)
- Linearizability
- Network partition
- Replication
- Eventual consistency
- Quorum
- Distributed consensus
- ACID
- Conflict resolution
Learn next
Write a timeline with two replicas, a completed write and a later read during a partition. Then specify what each user sees under a coordination-preserving policy and a policy that permits stale local responses.
More in Data engineering and architecture
- Cache-only memory architecture - Cache-only memory architecture, or COMA, is a shared-memory multiprocessor organization in which each node's main-memory capacity acts as a large cache of...
- Cache stampede - A cache stampede occurs when many requests encounter the same missing or expired cached value and independently try to fetch or recompute it.
- Candidate key - A candidate key is a minimal set of attributes that uniquely identifies a row in a relational data model.
- Cardinality (data modeling) - In data modeling, cardinality describes how many instances of one entity may or must be associated with an instance of another.
- Carrier cloud - A carrier cloud is cloud infrastructure or a cloud service associated with a telecommunications operator, often integrating computing and storage with the...
- Cartesian Product - The Cartesian product combines every element of one set with every element of another to form ordered pairs.
Sources
Primary sources: Gilbert and Lynch, Perspectives on the CAP Theorem, definitions and proof sketch: https://groups.csail.mit.edu/tds/papers/Gilbert/Brewer2.pdf ; Eric Brewer, CAP Twelve Years Later: How the Rules Have Changed: https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/ . Relevant author explanations reviewed. Status-value timeline and event-platform case are original illustrations.
Previous: Canonical Huffman code Next: Capability index, Cpk