Tradeoff
Sign inGet started

GuidesCAP theorem

The CAP theorem explained simply

10 min read · Updated 1 December 2026

Your app keeps a copy of its data in two regions, one in Mumbai and one in Frankfurt, so users everywhere get fast answers and one region can fail without taking you down. Every write in one region is copied to the other within a few hundred milliseconds.

Then the network link between the regions breaks. Both regions are still running. Users in both still send requests. A user in Frankfurt updates their address, and Mumbai cannot hear about it.

Now you have to decide something. Should Mumbai keep answering with data that might be out of date, or refuse until the link comes back? You cannot have both. That forced choice is the CAP theorem, and this guide explains it without the usual myths.

Key takeaways

  • CAP is about what happens during a network partition. Then you choose: stay consistent and refuse some requests, or stay available and risk stale or conflicting data.
  • It is not 'pick any two of three'. Partitions are not optional, so the real choice is C or A when one happens.
  • PACELC adds the everyday trade-off: even without a partition, stronger consistency costs latency.
  • Quorums let you tune the trade-off: with N copies, reads and writes overlap when R + W is greater than N.
  • Choose per feature, not per company: a bank balance and a likes counter need different answers.

The three letters, in plain words

CAP names three things you would like from data stored on several machines.

  • Consistency (C): every read sees the latest write. If Asha changes her address and then anyone reads it, from anywhere, they see the new address. Technically this is linearisability: the system behaves as if there were a single copy of the data.
  • Availability (A): every request to a working machine gets a real answer, not an error or a timeout. Even if some machines are cut off, the ones that are up still respond.
  • Partition tolerance (P): the system keeps running when the network between machines drops or delays messages. A network partition is exactly that: the machines are fine, but some cannot talk to others.

The theorem, first described by Eric Brewer and later proved by Seth Gilbert and Nancy Lynch, says this: when a partition happens, a system cannot be both consistent and available. It has to give up one of them until the network heals.

Why it is not 'pick two of three'

You will often see CAP drawn as a triangle with the advice "pick any two". That picture is misleading.

Here is why. A partition is not something you choose. Cables get cut, switches fail, a cloud region loses its link to another, a long garbage-collection pause makes one machine look dead. If your data lives on more than one machine, partitions will happen. So "CA" (consistent and available, but not partition tolerant) only really describes a system that runs on one machine, or one that simply breaks when the network does.

So the honest version is:

  1. 1.Most of the time there is no partition. A well-built system can be both consistent and available then.
  2. 2.When a partition happens, each side must choose. Either refuse requests it cannot be sure about (choose C) or answer with what it has and sort out the differences later (choose A).

That is all CAP says. It does not say a "CP" system is unavailable all the time, or that an "AP" system is always wrong. It only describes behaviour during the partition.

Step through the diagram to see both choices.

Client Anear region 1Replica Aregion 1Network linkbetween regionsReplica Bregion 2Client Bnear region 2

A normal write

Client A updates a value on replica A. The change travels over the link and replica B applies it a moment later. Both copies agree.

Consistency is a spectrum, not a switch

"Consistent" in CAP means the strictest kind. Real systems offer several levels in between, and knowing their names helps a lot in an interview.

  • Strong consistency (linearisable): once a write is confirmed, every later read anywhere sees it. Simple to reason about. Costs latency, because the write must reach enough copies before you confirm it.
  • Eventual consistency: if writes stop, all copies will agree after a while. In the meantime, two users may see different values. Fast and highly available.
  • Read-your-writes: you always see your own changes, even if other people see them a little later. Edit your profile, refresh, and your edit is there. This removes the most confusing kind of staleness for very little cost.
  • Monotonic reads: once you have seen a value, you never see an older one later. Without it, a refresh can make a new comment vanish and come back.

A common pattern: keep most data eventually consistent, but route a user's reads to the primary for a few seconds after they write, so they get read-your-writes. Most users never notice anything else.

PACELC: the trade-off you pay every day

CAP only talks about partitions, which are rare. But there is a cost you pay on every request, even when the network is healthy.

Say a write must reach a replica 150 ms away before you confirm it. That keeps the copies consistent, but every write now takes at least 150 ms. If you confirm as soon as the local copy has it, writes take 5 ms, but a read in the other region might briefly miss the change.

Daniel Abadi described this as PACELC: if there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency.

This is often the more useful lens. A system that "chooses availability" during a partition usually also chooses low latency day to day, because both come from not waiting for other copies. A system that refuses writes during a partition usually also makes every write wait for a majority. Saying "PA/EL" or "PC/EC" in an interview shows you understand the everyday cost, not just the rare failure.

Quorums: tuning the trade-off with numbers

Many databases let you choose how many copies must answer before a read or write counts. This is a quorum.

Let's say each value is stored on N = 3 replicas.

  • W is how many replicas must confirm a write.
  • R is how many replicas you ask on a read, taking the newest answer.

If R + W is greater than N, every read set overlaps every write set in at least one replica, so a read will normally include the latest confirmed write. With N = 3, W = 2 and R = 2 gives 2 + 2 = 4, which is more than 3. One replica can be down and both reads and writes still work.

Other settings move the dial:

  • W = 1, R = 1: fastest and most available, but reads can be stale.
  • W = 3, R = 1: reads are fast and fresh, but a single dead replica blocks all writes.
  • W = 2, R = 2: the usual balanced choice.

One honest caveat: overlapping quorums alone do not guarantee full linearisability in every edge case, for example with concurrent writes or "sloppy" quorums that borrow other nodes during failures. Systems that need strict consistency add a consensus protocol such as Raft or Paxos, where a majority must agree on the order of writes. Coordination services like etcd and ZooKeeper work this way, which is why the minority side of a partition stops accepting writes.

Real examples: choose per feature

The useful question is never "is our company CP or AP?". It is "what is the cost of a wrong answer here, versus the cost of no answer?" Different features in the same app often land on different sides.

  • Bank balance or stock count: showing money that is not there, or selling the last seat twice, is expensive and hard to undo. Refuse or delay during a partition. Choose consistency.
  • Likes counter or view count: if a post shows 1,204 likes instead of 1,207 for a few seconds, nobody is harmed. An error page would be worse. Choose availability.
  • Shopping cart: customers should always be able to add items. If two versions of a cart diverge during a partition, merge them, so an item is never lost. The cost is that a removed item can occasionally come back. Amazon's 2007 Dynamo paper used this exact example.
  • Usernames: two people must not claim the same name, even during a partition. Choose consistency for the "claim" step, while letting profile reads stay available.

Notice that "available" systems still need a plan for conflicts: what happens when both sides changed the same thing. Options include last-write-wins (simple, but loses one write), merging (as with the cart), or keeping both versions and letting the app or user decide.

DataDuring a partitionWhyTypical approach
Bank balanceRefuse or delay (CP)A wrong balance costs real moneySingle leader or consensus, strong reads
Seat or stock reservationRefuse (CP)Double-selling is hard to undoMajority writes, conditional updates
Likes or view counterAnswer (AP)Slightly stale numbers are harmlessLocal writes, merge counts later
Shopping cartAnswer (AP)Losing an add-to-cart loses a saleAccept writes, merge versions
User profile readsAnswer (AP), read-your-writesStale bio for seconds is fineReplicas plus reading own writes from the primary

How to talk about CAP in an interview

Interviewers rarely want a definition. They want to see you make the choice for a real piece of data and explain the cost. A good answer has three parts.

  1. 1.Name the data and the cost of being wrong. "Seat bookings: selling one seat twice means a refund and an angry customer."
  2. 2.Say what happens during a partition. "If a region loses contact with the primary, it rejects bookings and shows 'try again' rather than risk a double booking."
  3. 3.Say what you give up, and the everyday cost. "That costs availability in a rare failure, and every booking waits for a majority write, about 20 to 50 ms extra. Seat browsing stays eventually consistent and fast."

A few things to avoid:

  • Do not say "we pick CA". With more than one machine, partitions happen.
  • Do not label a whole product CP or AP. Label each feature.
  • Do not treat "eventual" as "broken". Say how long the lag usually is and how conflicts are resolved.

If you shard the data too, the choice applies per shard. The database sharding guide covers how data is split, and consistent hashing shows how replicas are placed.

Questions people ask

What is the CAP theorem in simple terms?

When the network between copies of your data breaks, a system has to choose. It can refuse some requests so nobody sees out-of-date data (consistency), or keep answering everyone and fix differences later (availability). It cannot do both while the partition lasts.

Is the CAP theorem really 'pick two out of three'?

Not really. Network partitions are not optional in a system that runs on several machines, so partition tolerance is a given. The real choice is between consistency and availability, and only while a partition is happening.

Is MongoDB or Cassandra CP or AP?

It depends on configuration more than on the product. Many databases let you tune how many replicas must confirm reads and writes, which moves them towards consistency or availability. In an interview, describe the settings you would choose for each feature rather than labelling the whole database.

What is the difference between CAP and PACELC?

CAP only describes behaviour during a partition. PACELC adds the normal case: even without a partition, you trade latency against consistency, because waiting for more replicas to confirm a write makes it slower.

What does R + W greater than N mean?

With N copies of each value, a write waits for W of them and a read asks R of them. If R plus W is more than N, the two groups always share at least one replica, so a read will normally see the latest confirmed write. N = 3 with R = 2 and W = 2 is a common setting.