Consistency

The CAP Theorem Without the Jargon

By NodeAccord Editorial Team · · 4 min read

The CAP theorem is often quoted in discussions of distributed databases, usually in a way that leaves newcomers more confused than before. "Pick two out of three" is a catchy slogan, but it hides what the theorem actually says and when it matters.

This article explains the idea with everyday language and one running example, then clears up the most common misunderstandings.

Setting the Scene

Suppose you run a service that stores data on two servers in different cities, so that one can take over if the other fails. Both servers hold a copy of every record, and users can talk to either one. This is a distributed system with replication.

Most of the time the servers communicate fine and stay in agreement. The theorem asks what happens when they cannot.

The Three Letters

Consistency means every read sees the most recent write. If you update your address on one server and immediately ask the other server for it, you get the new address, never the old one. To a user it feels like there is only one copy of the data.

Availability means every request to a working server gets a real answer, not an error or a timeout. The answer may not be the latest, but the system responds.

Partition tolerance means the system keeps working even when the network between its servers breaks, so that messages are dropped or delayed. A partition is that break.

The term consistency here is narrower than the one used in database transactions. In CAP it refers to agreement between copies of the data, often called linearizability.

What the Theorem Actually Says

The theorem states that when a network partition happens, a distributed system must choose between consistency and availability. It cannot fully provide both during that failure.

Return to the two servers. Imagine the link between the cities breaks, and a user updates their address on server one. Server two never hears about it. Now another request arrives at server two asking for that address. The system has two options.

  1. Refuse or wait. Server two says "I cannot confirm I have the latest data" and returns an error. The data stays consistent, but the system was not available.
  2. Answer anyway. Server two returns the old address. The system stayed available, but the answer was stale, so consistency was lost.

There is no third choice that satisfies both. That is the whole theorem.

Why It Is Not Really "Pick Two"

The slogan suggests you can pick any pair, like consistency and availability while dropping partitions. But partitions are not optional. Networks fail, cables break, and cloud zones lose connectivity. If your system spans more than one machine, you must tolerate partitions.

So the real decision is what to sacrifice during a partition.

  • CP systems prefer consistency. During a partition, some requests are rejected or delayed. These suit cases where wrong data is worse than no data, such as account balances or inventory counts.
  • AP systems prefer availability. They keep answering and reconcile differences later. These suit cases where being up matters more than being perfectly current, such as a social feed or a product view counter.

When no partition exists, a system can usually deliver both consistency and availability. CAP describes the trade-off under failure, not at every moment.

Eventual Consistency

AP systems typically offer eventual consistency. If no new updates occur, all copies will eventually agree. In the meantime, two users may briefly see different values.

Systems manage the mismatches in different ways. Some keep the write with the latest timestamp. Others store both versions and ask the application to merge them. Some use special data structures designed so concurrent edits combine without conflict.

Eventual consistency is not sloppy. Done well, it gives fast responses and strong uptime, and many everyday services rely on it.

Beyond CAP

CAP is a useful starting point but leaves out details that matter in daily design.

  • Latency: even without partitions, keeping copies in sync costs time. A related idea, sometimes called PACELC, notes that systems also trade latency against consistency when things are healthy.
  • Degrees of consistency: there is a spectrum between strict agreement and none. Options include read-your-own-writes and causal consistency.
  • Per-operation choices: some databases let you choose stricter or looser behavior for each query.

How to Use This When Choosing a Database

Ask what a wrong answer costs compared with no answer.

  1. If a stale read could cause real harm, lean toward consistency and accept occasional errors during outages.
  2. If downtime costs more than a slightly old value, lean toward availability.
  3. Check the documentation for how your chosen database behaves during a partition, and for settings that adjust it.
  4. Design your application to cope, for example by showing a pending status or retrying.

Frequently Asked Questions

Does CAP mean I can never have all three properties?

You can have all three while the network is healthy. The theorem only says that during a network partition you must give up either strict consistency or availability for the affected requests.

Is a single-server database affected by CAP?

Not in the usual sense. CAP concerns systems with multiple nodes that can be separated by a network failure. A single server has no partition between copies, though it can still fail entirely.

Is eventual consistency the same as being inconsistent?

No. It means copies may differ for a short time but are guaranteed to converge when updates stop. Applications designed for it handle the temporary differences deliberately.

Related reading