CAP as a Failure Trade-Off
📑 On this page
- A concrete example: a separated bank replica
- The three CAP terms
- Consistency in CAP
- Availability in CAP
- Partition tolerance
- The actual choice
- CP behavior
- AP behavior
- One system can make different choices
- Reads and writes differ
- Quorums
- Failure detection is imperfect
- PACELC
- CAP does not classify databases completely
- Eventual consistency is not automatically AP
- Business invariants
- User experience during partitions
- Recovery after a partition
- Testing partition behavior
- A practical CAP discussion
- Knowledge check
- The one idea to remember
CAP is often summarized as "pick any two: consistency, availability, partition tolerance."
That slogan is memorable but misleading. In a networked system, partitions can happen whether the designer wants them or not. The meaningful decision appears while communication is broken.
During a network partition, a distributed data operation cannot guarantee both immediate consistency and a successful response from every reachable side.
The design chooses which requests to reject, delay, or accept under uncertainty.
A concrete example: a separated bank replica
Two regions store an account balance. A network partition prevents them from communicating.
If both regions continue approving withdrawals based on the last known balance, the customer can overspend.
To preserve one authoritative balance order, at least one side must reject or delay uncertain writes. The system sacrifices some availability for that operation while partitioned.
The three CAP terms
CAP discusses:
- Consistency
- Availability
- Partition tolerance
These words have precise meanings in the theorem and should not be replaced casually with their everyday meanings.
Consistency in CAP
CAP consistency is commonly associated with linearizability.
Operations behave as if there were one up-to-date copy and one order consistent with real-time completion. After a write completes, later reads do not return an older value.
This is not the same as the "C" in ACID database transactions.
Availability in CAP
CAP availability means every request received by a non-failing node eventually gets a non-error response.
It does not promise:
- low latency,
- useful data,
- or a response before the user gives up.
A response containing stale state can count as available under the formal framing.
Partition tolerance
A partition means messages between groups of nodes are lost or delayed indefinitely from the system's perspective.
The nodes may continue running but cannot coordinate.
Partition tolerance means the system continues according to a defined policy despite that communication failure. For a truly distributed system, partitions are a condition to handle, not a decorative option to deselect.
The actual choice
When no partition exists, a system can often provide both consistency and availability.
During a partition:
- a CP-oriented operation rejects or delays some requests to preserve consistency,
- an AP-oriented operation accepts requests on multiple sides and reconciles later.
The choice is about behavior under the failure, not a permanent label for every moment.
CP behavior
A consistency-preferring design may require a quorum or leader before accepting a write.
If a node cannot prove it belongs to the authorized side, it rejects the request.
This avoids divergent accepted states, but users connected to the isolated side cannot complete the operation until communication or leadership recovers.
AP behavior
An availability-preferring design accepts operations on reachable nodes even when they cannot coordinate.
Replicas can diverge and must merge after the partition. The application needs:
- conflict rules,
- version history,
- commutative operations,
- or user reconciliation.
Availability transfers complexity into convergence and business semantics.
One system can make different choices
A product is rarely simply "CP" or "AP."
Examples:
- account-balance writes may reject under uncertainty,
- product browsing can serve stale cache,
- social reactions can accept concurrent updates,
- permission revocation may require strong authority,
- shopping carts can merge item additions.
Choose guarantees per operation and invariant.
Reads and writes differ
During a partition, a service may:
- serve stale reads but reject writes,
- permit reads only from a leader,
- accept local writes for later merge,
- or distinguish high-risk and low-risk fields.
The same data store can expose several consistency levels. Client behavior and business requirements select among them.
Quorums
Replicated systems may use:
N: number of replicas,W: write acknowledgments required,R: read responses consulted.
When W + R > N, read and write quorums overlap under ideal assumptions, helping locate a recent value.
Real correctness also depends on versioning, failure detection, sloppy quorums, clock behavior, and implementation details. The inequality is not a complete design proof.
Failure detection is imperfect
A slow node and a partitioned node can look identical.
Systems use timeouts and heartbeats to suspect failure, but suspicion can be wrong. Declaring a new leader while the old leader still accepts writes can create split brain.
Consensus protocols coordinate leadership and commit decisions under defined fault assumptions.
PACELC
CAP focuses on partitions.
PACELC adds another useful observation:
- if Partition, choose Availability or Consistency;
- Else, often choose Latency or Consistency.
Even in healthy networks, stronger coordination can add latency. This framing helps discuss ordinary-operation tradeoffs as well as failures.
CAP does not classify databases completely
A database may offer:
- strongly consistent writes,
- eventually consistent secondary reads,
- tunable consistency,
- regional failover,
- and transactions with specific scopes.
Calling the whole product "AP" or "CP" hides important configuration and operation-specific guarantees.
Read the documented failure semantics.
Eventual consistency is not automatically AP
A system can return stale data in healthy conditions yet still become unavailable during some partitions.
Similarly, an available system needs a defined merge behavior to remain useful after accepting divergent writes.
CAP labels should not replace analysis of actual protocols and user outcomes.
Business invariants
The right choice begins with an invariant:
- never spend the same funds twice,
- do not grant access after revocation,
- preserve every comment,
- keep cart additions,
- or show the newest profile when possible.
Then ask what the system may do when coordination is unavailable.
Formal consistency serves business correctness; it is not the final product requirement by itself.
User experience during partitions
A consistency-preferring product should explain:
- "Transfers are temporarily unavailable."
An availability-preferring product may say:
- "Saved locally; syncing when connection returns."
Both are more honest than silent failure or pretending uncertain state is final.
Recovery after a partition
When communication returns, systems may need to:
- elect an authoritative history,
- merge concurrent updates,
- replay logs,
- repair replicas,
- compensate invalid business effects,
- and notify users about conflicts.
The partition policy is incomplete without the recovery policy.
Testing partition behavior
Test with intentional network separation:
- isolate replicas,
- delay messages,
- allow leaders to restart,
- perform reads and writes on each side,
- restore communication,
- and verify convergence or rejection rules.
Killing a process is not equivalent to partitioning it; a partition leaves multiple sides alive.
A practical CAP discussion
For each important operation, ask:
- What invariant must hold?
- Which nodes can accept it?
- What happens when they cannot communicate?
- Can a stale response be useful?
- Can concurrent updates merge?
- What does the user see?
- How does recovery restore a valid state?
This is more useful than assigning one two-letter label to an architecture.
Knowledge check
- Why is "pick any two" an incomplete explanation of CAP?
- What does availability mean in the theorem?
- How does a consistency-preferring system behave during a partition?
- Why can one product choose differently for balances and reaction counts?
- What additional tradeoff does PACELC highlight?
The one idea to remember
CAP describes a forced choice during network partition: preserve immediate consistency by rejecting or delaying some requests, or remain available by accepting possible divergence. Make that choice per operation according to business invariants, user experience, and recovery behavior.