CAP Theorem Explained: Why You Cannot Have It All

CAP theorem explained in plain terms means understanding why a distributed system cannot promise everything at once. The central question is what a system should do when its machines cannot talk to each other, and the answer is that it must give up either always agreeing or always answering, because it cannot do both while the network is broken.

CAP is short for consistency, availability, and partition tolerance, three properties of a distributed system. The theorem, proposed by Eric Brewer in 2000 and proved by Seth Gilbert and Nancy Lynch in 2002, says that when a network partition happens, a system can guarantee at most two of the three, and in practice it must choose between consistency and availability.

The idea is simple: if two groups of machines cannot communicate, neither group knows what the other has done. One group can stop answering until the network heals, keeping every answer correct, or it can keep answering with what it knows, accepting that its answers may be out of date. This article explains what the CAP theorem is, how it works, and where it is used.

Key takeaways

  • CAP stands for consistency, availability, and partition tolerance.
  • A network partition is when machines cannot communicate with each other.
  • During a partition, a system must choose consistency or availability.
  • Partition tolerance is not optional in a real distributed system.
  • The real choice is how a system behaves when the network breaks.

What the CAP theorem is

Consistency, in the CAP sense, means that every read receives the most recent write, or an error. If one machine records a change, any machine asked afterwards must show that change, so that all readers see the same data at the same time. It is a strong promise, and it is the one most people mean when they say a system is consistent.

Availability means that every request receives a response, even if that response is not the most recent value. A system that is available never refuses to answer, and never makes a client wait indefinitely, which matters when a service must keep serving users through a failure, however imperfect the answer may be.

Partition tolerance means the system keeps working even when the network splits and some machines cannot reach others. A partition is not a rare disaster but a normal failure in a distributed system, since networks drop messages and servers lose contact. Our guide to distributed systems explains why these failures are unavoidable, and our guide to ACID explains the stricter guarantees that single databases offer inside one machine.

How the CAP theorem works

Imagine a database copied onto two servers, and a network failure cuts the link between them. A client writes a new value to the first server, and another client then reads from the second server, which has not heard about the write. The system now faces a choice, and there is no way to avoid making it.

If the system chooses consistency, the second server must refuse to answer, or wait until it can check with the first server, because any answer it gives would be out of date. The read fails or stalls, so availability is lost, but no client is ever told a stale value. The system stays correct, at the cost of being unreachable for a while.

If the system chooses availability, the second server answers with the old value it still holds. The client gets a reply at once, so availability is kept, but the answer is wrong in the sense that it misses the latest write. The system stays reachable, at the cost of letting different readers see different values until the network heals.

Partition tolerance is the property that forces the choice. A system that is not partition tolerant simply stops when the network breaks, which is no choice at all, but a real distributed system must keep some part of itself running, so it must decide which promise to break. That is why the theorem is often stated as a choice between consistency and availability, with partition tolerance taken as given.

The choice is not fixed forever, and it is not made once for the whole system. Different parts of a system can make different choices, and the same system can behave differently in normal operation, when all three properties hold at once, than it does during a partition. The theorem only bites when the network actually breaks, which is when the trade-off becomes real.

Two server racks in a dark room separated by a broken glowing cable with a green light on each side
Two server racks divided by a broken cable show how the CAP theorem works: when the link fails, a system must choose between agreeing and answering.

Comparing CAP with other design choices

The CAP theorem is one of several ways to think about trade-offs in distributed systems, and each approach suits a different need. Consistency-first systems protect correctness, availability-first systems protect uptime, and a single-machine system avoids the trade-off entirely, but only by giving up distribution.

The table below sets out the main contrasts between the leading approaches.

Aspect Consistency-first Availability-first Single machine
During a partition Refuses some requests Answers with old data No partition possible
Reads after write See the new value at once May see the old value See the new value at once
Use case Money, inventory Feeds, shopping carts Small applications
Cost Downtime during failures Stale reads, conflicts One point of failure
Best for Correctness first Uptime first Simplicity first

The practical result is that consistency-first is the right choice when a wrong answer is worse than no answer, availability-first wins when a service must keep responding through a failure, and a single machine is the choice only where the data is small enough that distribution is not needed.

Where the CAP theorem is used

Banking systems choose consistency. A bank cannot tell two branches different balances for the same account, so when the network between them fails, the safer course is to refuse transactions until the link is restored, rather than risk spending money that is not there.

Social networks and content feeds choose availability. A feed that shows a post a few seconds late is a small annoyance, while a feed that refuses to load at all drives users away, so these systems keep answering through a partition and let the copies catch up afterwards.

Shopping carts often choose availability, with consistency applied later. A customer should be able to add an item to a cart even if one data centre cannot reach another, and the system can reconcile the cart when the network heals, rather than blocking the sale in the meantime.

Domain name systems choose availability on a vast scale. A name lookup must answer quickly from a nearby server, even if that server has not yet received the latest change, because a slow or refused answer would break far more than a briefly out-of-date record would.

Any team designing a distributed system uses the CAP theorem as a starting point for its decisions. It does not tell the team what to choose, but it stops the team from promising all three properties at once, and it frames the honest question, which is what the system should do when the network breaks.

Strengths and limits

The greatest strength of the CAP theorem is its clarity. It takes a confusing tangle of failures and trade-offs and reduces it to a single choice, which makes it far easier for a team to agree on what a system should do, and far harder for a design to promise what it cannot deliver.

It is also a strength that the theorem is proved, not just observed. Gilbert and Lynch showed formally that no system can guarantee all three properties during a partition, so the limit is a fact about distributed systems, not a shortcoming of any particular database or design.

The limits are real, though. The theorem says nothing about how a system should behave when the network is healthy, it treats consistency and availability as all or nothing when real systems offer shades of both, and it says nothing about latency, which is often the trade-off that matters most in practice. It is a starting point for design, not a complete guide to it.

CAP theorem checklist

  • Decide what your system does during a partition, before it happens.
  • Choose consistency where a wrong answer costs more than no answer.
  • Choose availability where a refused answer costs more than a stale one.
  • Remember that partition tolerance is not optional in a real system.
  • Apply different choices to different parts of the system where it fits.
  • Plan how copies reconcile once the network heals.
  • Test the system with the network cut, not only with servers stopped.
  • Watch for stale reads, since they are the first sign of a bad trade-off.
  • Revisit the choice as the product and its users change.

Frequently asked questions

What is the CAP theorem in simple terms?

The CAP theorem says a distributed system cannot guarantee consistency, availability, and partition tolerance all at once during a network partition. When machines cannot talk to each other, the system must choose between always agreeing and always answering.

Who proposed the CAP theorem?

Eric Brewer proposed the CAP theorem in 2000. Seth Gilbert and Nancy Lynch proved it in 2002, showing formally that no system can guarantee all three properties when the network is partitioned.

What is a network partition?

A network partition is when some machines in a distributed system cannot communicate with others, because a link has failed or messages are being dropped. The machines on each side keep running, but neither side knows what the other is doing.

Can a system have all three CAP properties?

Yes, when the network is healthy, all three can hold at once. The theorem only applies during a partition, when the system must give up either consistency or availability until the network heals.

What is the difference between CAP and ACID?

ACID is a set of guarantees for transactions inside a single database, while CAP is about the trade-offs of a system spread across many machines. A system can offer ACID transactions and still face the CAP choice when its machines cannot communicate.

How do I choose between consistency and availability?

Ask what a wrong answer would cost. If a stale or conflicting answer could lose money or break trust, choose consistency. If refusing to answer would lose users or sales, choose availability, and plan how the data will catch up afterwards.

The bottom line

The CAP theorem explained in one line is this: when the network breaks, a distributed system must choose between always agreeing and always answering, because it cannot do both.

It is the trade-off at the heart of distributed design, and it remains the first question any team should answer before choosing a database or building a system that spans more than one machine.

This article is general information about how the CAP theorem works, not advice about choosing a database for a particular system.

Latest articles

Scroll to Top