Articles

CAP Theorem Explained: Consistency vs Availability

CAP theorem says a distributed system can't guarantee consistency, availability, and partition tolerance all at once. What the trade-off means in practice.

Chisato Chisato · · 4 min read
Abstract illustration of database nodes

CAP theorem states that a distributed data system can provide at most two of three guarantees at the same time: consistency, availability, and partition tolerance. Since network partitions are a fact of life in any system spread across multiple machines, the theorem in practice reduces to a single question: when a partition happens, does your system favor consistency or availability? Every distributed database ends up on one side of that line, whether or not its designers frame it that way.

The three properties

  • Consistency — every read receives the most recent write, or an error. All nodes see the same data at the same time; there’s no such thing as reading stale data from a replica that hasn’t caught up.
  • Availability — every request receives a non-error response, without a guarantee that it contains the most recent write. The system stays responsive even if some nodes can’t communicate.
  • Partition tolerance — the system continues to operate despite network partitions, meaning messages between nodes can be dropped or delayed arbitrarily.

The theorem’s actual claim is narrower than it’s often summarized: it’s not that you pick any two of three in general. It’s that when a partition actually occurs, you must choose between consistency and availability — you cannot have both while nodes can’t talk to each other. Partition tolerance itself isn’t really optional for a system distributed across more than one machine, because networks fail; the real decision point is CP versus AP under partition.

What happens during a partition

Imagine a database replicated across two data centers, and the network link between them goes down. A client writes to the data center in Region A. Another client, moments later, reads from the data center in Region B. What should happen?

  • Choose consistency (CP): Region B refuses the read, or blocks until the partition heals and it can confirm it has the latest data. The system is correct but temporarily unavailable for some requests.
  • Choose availability (AP): Region B serves the read anyway, using whatever data it currently has — which might be stale, since it hasn’t heard about Region A’s write. The system stays responsive but can return outdated or conflicting data.

There’s no third option that gives you both a fresh answer and a guaranteed answer while the two regions can’t communicate. That’s the theorem, and it’s a mathematical result, not an engineering shortfall — no amount of clever implementation removes the trade-off, only shifts where and how visibly it’s paid.

CP vs AP in practice

CP systemsAP systems
Behavior during a partitionReject or block some requests to stay correctKeep serving requests, may return stale data
Typical use caseFinancial transactions, inventory counts, anything needing strict correctnessShopping carts, social feeds, session data, anything tolerating brief staleness
Examples of the modelTraditional relational databases run with strong consistency, distributed lock servicesDNS, many NoSQL stores configured for high availability
Failure mode”Service temporarily unavailable""You might see slightly old data”

Most systems aren’t purely one or the other — many databases let you tune the trade-off per-operation or per-table. SQL vs. NoSQL databases historically split along roughly these lines, though the line has blurred as relational systems added distributed and eventually-consistent modes, and NoSQL systems added stronger consistency options.

Eventual consistency

AP systems commonly adopt eventual consistency: after a write, all replicas will converge to the same value eventually, once the partition heals and updates propagate — but there’s no bound on exactly when. This is weaker than the strong consistency a CP system guarantees, but it’s often good enough, and it buys availability that a CP system gives up. Database replication strategies largely exist to manage exactly this trade-off: how fast, and how strictly, do replicas need to agree.

Where CAP shows up outside the database layer

CAP theorem is usually taught in the context of databases, but the same trade-off appears anywhere state is distributed and partitions are possible. Database sharding splits data across nodes for scale, and each shard boundary is a place the CAP trade-off can bite if a shard becomes unreachable. Vector databases built for large-scale similarity search often lean AP, favoring availability and accepting eventual consistency, since a slightly stale nearest-neighbor result is rarely catastrophic. Systems built for edge deployment, where data lives close to users across many geographically separate nodes, live with network partitions as a routine condition rather than a rare failure — which pushes most of them toward the AP side by design.

The takeaway

CAP theorem isn’t a checklist you satisfy — it’s a constraint you can’t escape once data is distributed across a network that can partition. The real decision is what your system does when a partition happens: block and stay correct (CP), or respond and risk staleness (AP). Neither choice is universally right; a payments ledger and a product recommendation feed have very different tolerances for stale reads, and that difference should drive which side of CAP a given system lands on.

The Lycoris Team The Lycoris Team · · 5 min read

The Raft Consensus Algorithm, Explained

Raft is a consensus algorithm that lets a cluster of servers agree on a shared state even when some nodes fail. How leader election and log replication work.

#Distributed Systems #Computer Science #Databases
The Lycoris Team The Lycoris Team · · 5 min read

What Is Two-Phase Commit (2PC)? Distributed Transactions

Two-phase commit coordinates a transaction across multiple databases with a prepare phase and a commit phase, trading availability for strong consistency.

#Databases #Distributed Systems #Computer Science