Skip to content
Velloreth
Technology 5 min read

CAP Theorem Explained: Consistency, Availability, Partitions

A distributed system can have two of three. Learn what the theorem actually says, the common misreading, and the PACELC extension.

By

The theorem

A distributed system cannot guarantee all three of:

  • Consistency — every read sees the most recent write
  • Availability — every request gets a response
  • Partition tolerance — the system keeps working when a message is lost

The key insight: a network partition is a fact, not a choice. A cable is cut, a switch fails, a packet is dropped. So the real decision is what the system does during a partition.

The common misreading

“Pick two of three” is misleading.

Why: the trade-off only applies during a partition. When the network is healthy, a system can be both consistent and available.

The accurate statement: during a partition, choose consistency or availability.

Network healthy  ->  consistent AND available
Network partition ->  consistent OR available

Most systems are not purely one or the other. A database can be configured to require a quorum for a write, which makes it CP, or to accept a write on any node, which makes it AP.

CP

A CP system refuses a request it cannot serve consistently.

The behaviour during a partition: the minority side stops accepting writes, so the data stays correct and the service is unavailable on that side.

The examples: a system with a quorum write, a consensus-based store, a relational database with synchronous replication.

The use case: a bank balance, an inventory count, a unique username.

The cost: an unavailable service during a partition.

AP

An AP system answers with the data it has.

The behaviour during a partition: both sides accept writes, and the values diverge. The conflict is resolved later.

The examples: a Dynamo-style store, a multi-master replication, a cache.

The use case: a social feed, a product catalogue, a like count.

The cost: a stale read, and a conflict to resolve.

The conflict resolution: last-write-wins, a vector clock, or a merge function.

The comparison

ConcernCPAP
During a partitionrefuseanswer
Datacorrectpossibly stale
Availabilityreducedkept
Conflictnonemust be resolved
Examplebank balancesocial feed

PACELC

CAP covers only the partition case. PACELC extends it.

If Partition, choose Availability or Consistency; Else, choose Latency or Consistency.

The insight: even without a partition, a consistent write must wait for a quorum, which adds latency.

The trade-off in the normal case:

  • A consistent read waits for the replicas to agree, which is slower
  • A fast read may return a stale value

The examples:

SystemPartitionNormal
DynamoDBPAEL
CassandraPAEL
MongoDB (majority)PCEC
SpannerPCEC

A system that is PC/EC is consistent in both cases and pays with availability and latency.

The consistency spectrum

Consistency is not binary. The useful levels:

Strong consistency — every read sees the latest write.

Read-your-writes — a client sees its own writes.

Monotonic reads — a client never sees an older value than one it already saw.

Eventual consistency — the replicas converge, with no bound on the delay.

Causal consistency — a write that depends on another is seen after it.

The practical point: a system can offer a weaker guarantee and a better latency, and the application may not need the strongest one.

Quorums

A quorum is the number of nodes that must agree.

N = replicas
W = nodes that must acknowledge a write
R = nodes that must respond to a read

If W + R > N, a read sees the latest write.

The configurations:

WRProperty
N1fast read, slow write, consistent
1Nfast write, slow read, consistent
majoritymajoritybalanced
11fast, eventually consistent

A quorum is how a system is tuned between consistency and latency without changing the code.

Choosing

A payment or an inventory: CP. A stale value is worse than an error.

A feed or a catalogue: AP. A stale value is acceptable and an error is not.

A session store: AP with a short TTL.

A configuration store: CP, because a wrong configuration is worse than a delay.

The question to ask: what happens if this value is stale for a second? If the answer is “nothing”, AP is fine.

Common mistakes

Saying “we chose AP and CA”. CA is not an option in a distributed system, because a partition happens.

Applying CAP to a single node. There is no partition to tolerate.

Assuming eventual consistency means no consistency. It means the replicas converge, and the application must tolerate the window.

Ignoring the latency trade-off. PACELC is the part that applies every day.

A quorum that is not a majority. Two quorums can overlap incorrectly and a read can miss a write.

Treating the choice as permanent. Most systems are tunable per operation.

Forgetting the conflict resolution. An AP system that accepts divergent writes must have a merge rule.

A quotable summary

The CAP theorem says a distributed system cannot guarantee consistency, availability and partition tolerance at the same time, and since a partition is a fact, the real decision is what the system does during one: refuse the request to stay consistent, or answer with possibly stale data to stay available. PACELC extends it to the normal case, where a consistent write must wait for a quorum and therefore costs latency. Most systems are tunable rather than purely CP or AP, and the right choice depends on the cost of a stale read against the cost of an unavailable service.

For the related topics, see eventual-consistency-guide and replication-vs-sharding. For the broader context, database-sharding-basics and transactions-and-acid.

Frequently asked questions

What does the CAP theorem say?
It says a distributed system cannot guarantee consistency, availability and partition tolerance at the same time. Since a network partition is a fact rather than a choice, the real decision is what the system does during a partition: refuse the request to stay consistent, or answer with possibly stale data to stay available.
What is the common misreading of CAP?
The common misreading is that a system picks two of three permanently. In fact the trade-off only applies during a partition. When the network is healthy, a system can be both consistent and available, and most systems are.
What is the difference between CP and AP?
A CP system refuses a request it cannot serve consistently, so it stays correct and may be unavailable. An AP system answers with the data it has, so it stays available and may return a stale value. A bank balance is usually CP and a social feed is usually AP.
What is PACELC?
It extends CAP to cover the normal case. If there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency. It captures the trade-off that exists even when the network is healthy, because a consistent write must wait for a quorum.
Is a single database subject to CAP?
A single-node database is not, because there is no partition to tolerate. CAP applies to a distributed system with more than one node. A replicated database is subject to it, and the replication configuration determines the behaviour.
Which is better, CP or AP?
Neither. The right choice depends on the cost of a stale read against the cost of an unavailable service. A payment system prefers consistency, and a product catalogue prefers availability. The decision is a product decision as much as a technical one.