What is CAP theorem?

In short
The CAP theorem says a distributed database cannot fully guarantee consistency, availability, and partition tolerance at the same time. When the network splits, a system must choose between giving accurate answers and staying responsive. Partition tolerance is required in any distributed system, so the real choice is between consistency and availability.
The three properties
A distributed database stores data across several servers, called nodes. Each node keeps a copy of some or all of the data, and the copies must be kept in sync. The CAP theorem describes three properties such a system can have.
Consistency means every node shows the same, most recent data. Once a write is accepted, any reader should see it, no matter which node they ask. Strong consistency usually means the system waits until enough nodes agree before it confirms a write. That protects accuracy, but it can slow things down.
Availability means the system keeps answering requests, even when some nodes are down or behind. An available system may return slightly stale data, but users are not blocked.
Partition tolerance means the system keeps working when the network splits. A partition happens when nodes can no longer talk to each other, while each side is still running.
What the theorem actually says
The theorem was introduced by Eric Brewer. The first version was often summarized as "pick two of three." In 2012, Brewer clarified that this summary was too simple. A partition is not a choice you get to skip, because networks fail. So the real question is what the system does while a partition lasts. It must either refuse some requests to keep data consistent, or answer them and reconcile the copies later.
This is why the theorem is best read as a rule about behavior during failures, not a fixed label for a product. Normal operation can be both consistent and available. The trade-off appears only when nodes lose contact.
How it works in practice
Consider two very different applications. A chat app spread across regions usually chooses availability. If messages from one region are delayed, the rest of the conversation keeps going, and the delayed region catches up once the connection returns.
A bank transfer usually chooses consistency. If the network breaks in the middle of a transfer, the system can stop the operation until all records agree. This prevents duplicate entries or mismatched balances, at the cost of a failed or delayed request.
Designers pick the behavior that fits the data. Money and inventory tend to need accuracy. Feeds, analytics and social features often favor staying online.
CA, CP and AP systems
Because partitions cannot be avoided in a distributed setting, databases are often grouped by the two properties they emphasize.
CA systems provide consistency and availability when the network is healthy. During a partition, they cannot keep both, so they stop serving the split nodes until the connection is restored. Traditional single-site relational setups are often described this way.
CP systems keep data consistent during partitions. They delay responses until updates are confirmed, so some requests may fail or wait. Many configurations of MongoDB fall into this group.
AP systems stay available during partitions. They may return data that is slightly out of date, and they reconcile the copies afterwards. Some wide-column and key-value stores are built this way.
These labels describe typical behavior. Many modern databases let you tune the trade-off per operation rather than fixing it once for the whole system.
Tunable settings in MongoDB
MongoDB runs replica sets, where one primary node takes writes and secondary nodes keep copies. Two settings let developers adjust the balance. The write concern controls how many replicas must confirm a write before the client gets success. A value of "majority" favors consistency. A lower value favors speed and availability.
The read preference controls where reads are sent. Reading from the primary gives the most current data. Reading from secondaries can spread load and keep reads working when the primary is unavailable, but the data may be slightly behind.
db.orders.insertOne(
{ item: "keyboard", qty: 2 },
{ writeConcern: { w: "majority" } }
)
The example asks for acknowledgment from a majority of replicas before the write is reported as successful. This is a common choice for data that must not be lost or duplicated.
Common mistakes
A frequent mistake is treating CAP as a one-time product choice. Another is assuming a system without partitions has no trade-offs at all. Partitions still matter for design, even when they are rare.
Developers also sometimes ignore defaults. A database may be set to acknowledge writes before they reach every replica, which changes the consistency you actually get. Check write and read settings against what your application needs.
Finally, do not read CAP as a score. It does not say one system is better. It says which guarantee gives way when the network fails, and that answer depends on your workload.
Where to go next
If you are new to how data is spread across machines, start with the basics of distributed databases and replication. Then return to the trade-offs above and map them to your own data, asking which wrong answer would hurt more: a stale read, or a request that fails.
FAQ
Is the CAP theorem still relevant for modern databases?
Yes, it remains a useful way to reason about failures in distributed systems. Many modern databases expose settings that let you choose the trade-off per operation.
Why can't a system just have all three properties?
During a network partition, nodes cannot coordinate. A system must either wait and refuse some requests to stay consistent, or answer them and risk out-of-date data.
Does choosing CP mean the system is always unavailable?
No. CP systems remain available when the network is healthy. They only limit or delay certain operations while a partition is happening.
What is the difference between a CP and an AP system in practice?
A CP system may reject or delay a request to protect accuracy. An AP system answers the request, possibly with slightly stale data, and fixes differences later.
Sources
This page is based on the official documentation below. Read it for full detail.
CAP theorem — official documentation ↗