CAP Is Not 'Pick Any Two': The CAP Theorem Without Myths
Partitions aren't optional, CAP's C and A are narrower than their names, and the real choice is made per operation, during a partition, and against latency the rest of the time.
In a design review, someone asks why the team picked a particular database for its new flight-booking service. The answer comes quickly: "It's AP, and we need availability." Everyone nods. A few months later, a network problem between two regions lets travelers in both regions book the same seat, and support spends a week rebooking people. The label was accurate as far as it went. It just answered the wrong question, for the whole system at once.
The common misconception
The belief: CAP lets a system designer pick any two of consistency, availability and partition tolerance. Pick C and A for a classic database, A and P for a NoSQL store, C and P for a consensus system, and you're done.
It's not an invented myth. Eric Brewer, who introduced the idea, summarized it this way himself: "any networked shared-data system can have at most two of three desirable properties". Many diagrams draw it as a triangle with a choice of sides. But in 2012 Brewer wrote: "The '2 of 3' formulation was always misleading because it tended to oversimplify the tensions among properties."
What actually happens
Partition tolerance isn't optional
A is the network between some nodes failing while the nodes keep running. Martin Kleppmann describes partition tolerance as "communicating over an asynchronous network that may delay or drop messages. The internet and all our datacenters have this property, so you don't really have any choice in this matter." Brewer makes the same point about choosing "CA": "If the choice is CA, and then there is a partition, the choice must revert to C or A."
So the real statement is narrower: when a partition happens, you can't have both C and A. When there's no partition, CAP says nothing stops you from having both.
The proof fits in two nodes
Seth Gilbert and Nancy Lynch proved Brewer's conjecture in 2002. Their says it's "impossible in the asynchronous network model to implement a read/write data object" that guarantees both availability and atomic consistency in all executions, "including those in which messages are lost." The idea: split the nodes into two groups and lose every message between them. A write completes on one side, and a later read arrives on the other. If that side answers, it returns the old value; to stay correct, it must not answer. Brewer: "Allowing at least one node to update state will cause the nodes to become inconsistent, thus forfeiting C. Likewise, if the choice is to preserve consistency, one side of the partition must act as if it is unavailable, thus forfeiting A."
C and A mean less than their names
CAP's C is : informally, once a write completes, any read that starts afterwards sees it or something newer. Kleppmann stresses that "it has got nothing to do with the C in ACID". CAP's A is strict too. Gilbert and Lynch define it as "every request received by a non-failing node in the system must result in a response", with no time limit. A system that answers in two minutes is CAP-available; one whose nodes on the minority side of a partition refuse writes isn't, even if your uptime is excellent.
By those definitions, many real systems are neither. Kleppmann's example is the usual single-leader database: clients cut off from the leader can't write, and reads from asynchronous followers may be stale. "They are neither 'CP' nor 'AP', they are just 'P'".
The choice is per operation, and mostly about time
Brewer: "the choice between C and A can occur many times within the same system at very fine granularity", even changing "according to the operation or even the specific data or user involved." In practice the choice happens during a timeout, which he calls the partition decision: "cancel the operation and thus decrease availability, or proceed with the operation and thus risk inconsistency."
Daniel Abadi adds the part CAP leaves out. His PACELC asks two questions: during a partition, availability or consistency; "else (E), when the system is running normally in the absence of partitions, how does the system trade off latency (L) and consistency (C)?" Reading from a nearby replica is that trade, made every day with no failure at all.
The fix: decide per operation
C# · Seats.cs
// "We picked AP", so every call goes to the nearest regionpublic sealed class Seats(ISeatStore nearest){ // During a partition, two regions can each sell the same seat public Task<bool> BookAsync(Guid flight, string seat, CancellationToken ct) => nearest.TryAssignAsync(flight, seat, ct); public Task<string[]> FreeSeatsAsync(Guid flight, CancellationToken ct) => nearest.GetFreeSeatsAsync(flight, ct);}
C# · Seats.cs
public sealed class Seats(ISeatStore primary, ISeatStore nearest){ // A seat must never be sold twice, so only the primary region decides. // If it can't answer in time, fail and let the user try again (C over A) public async Task<bool> BookAsync( Guid flight, string seat, CancellationToken ct) { using var cts = CancellationTokenSource.CreateLinkedTokenSource(ct); cts.CancelAfter(TimeSpan.FromSeconds(2)); // the time bound return await primary.TryAssignAsync(flight, seat, cts.Token); } // The seat map may be seconds old: the nearest region answers fast, // even during a partition (A and low latency over C) public Task<string[]> FreeSeatsAsync(Guid flight, CancellationToken ct) => nearest.GetFreeSeatsAsync(flight, ct);}
The same service now makes two choices, each matching what the operation can afford. Booking pays for consistency with latency, and with failures when the primary region is out of reach. Browsing stays fast and available, and a seat that looked free but was just sold is caught by the booking step. A timed-out booking is an unknown outcome, as an earlier article in this path explained, so check the traveler's booking before trying again.
Myth
Reality
You can pick any two of C, A and P
Partitions happen anyway; during one, each operation gives up C or A
A distributed database can be "CA"
Brewer: if there's a partition, "the choice must revert to C or A"
CAP's C is ACID's C
It's linearizability: a read sees the latest completed write
CAP's A means high uptime
Every non-failing node must answer, with no time limit
Every database is either CP or AP
Many are neither, and the choice varies by operation and setting
How to apply it in your project
List operations, not databasesWrite down each important read and write, such as booking a seat, showing a seat map or updating a profile, instead of labeling the whole system.
Decide what each does when it can't reach the other sideFor each operation pick one: wait and fail (consistency), answer from local data (availability), or accept now and reconcile later.
Set the time bound on purposeBrewer calls a partition "a time bound on communication". Choose each operation's timeout from the user's wait, knowing a tighter bound means entering partition mode more often.
Check what your database actually guaranteesRead its consistency documentation and configuration, such as replica reads, quorum settings or consistency levels, rather than trusting a CP or AP label.
Key takeaways
CAP isn't "pick any two": partitions happen, and during one each operation gives up consistency or availability.
CAP's C is linearizability and its A is "every non-failing node answers", both narrower than everyday usage.
Many real systems are neither CP nor AP, so labels hide more than they explain.
Make the choice per operation, and treat the timeout as the moment of decision.
Outside partitions, the everyday trade is consistency against latency, which CAP doesn't cover and PACELC does.
التعليقات (0)