# CAP Theorem (Consistency, Availability, Partition Tolerance)

URL: https://softwaredictionary.org/terms/cap-theorem
Category: Databases
Last updated: 2026-09-30
In Turkish: CAP Teoremi
Pronunciation: KAP THEER-um

In short: The CAP theorem says that if a network failure splits a distributed database, the system must choose between consistency and availability; it can't have both.

## What is the CAP theorem?

The CAP theorem describes a fundamental trade-off in distributed data systems, meaning databases that store data on several networked machines. It names three properties: consistency (every read returns the most recent write or an error), availability (every request to a working node gets a non-error response), and partition tolerance (the system keeps working even when network failures cut some nodes off from others). It was proposed by Eric Brewer in 2000 and proven by Seth Gilbert and Nancy Lynch in 2002.

It is often summarized as 'pick two of three', but that is misleading. Network partitions can't be prevented in a real distributed system, so partition tolerance is not optional, and the actual choice is what to do while a partition lasts. A CP system refuses or delays some requests to avoid returning stale data, while an AP system keeps answering but may return out-of-date data until the network heals.

Imagine two bank branches that lose their phone line to each other. Either they stop allowing withdrawals until the line is back, choosing consistency, or they keep serving customers and reconcile balances later, choosing availability and risking an overdraft. Systems that handle payments or inventory often lean CP, while shopping carts, social feeds, and DNS usually lean AP and rely on eventual consistency, where all copies converge once communication is restored.

Two confusions are worth knowing. The C in CAP means linearizability, a strict guarantee that every node returns up-to-date data, which is different from the C in ACID, where consistency means the data follows the database's rules and constraints. And CAP only describes behavior during partitions; the PACELC theorem extends it by noting that even when the network is healthy, systems trade latency against consistency.

## Key takeaways

- CAP stands for consistency, availability, and partition tolerance.
- During a network partition, a distributed system must choose consistency or availability.
- Partition tolerance is mandatory in practice, so the real choice is CP or AP.
- The C in CAP is not the same as the C in ACID.
- PACELC extends CAP to the latency-versus-consistency trade-off in normal operation.

## Example: Choosing consistency or availability per query in Apache Cassandra

```sql
-- In cqlsh, the Cassandra shell, the trade-off can be tuned per request

-- Favors availability: any single replica may answer, possibly with stale data
CONSISTENCY ONE;
SELECT balance FROM accounts WHERE id = 42;

-- Favors consistency: a majority of replicas must respond, or the read fails
CONSISTENCY QUORUM;
SELECT balance FROM accounts WHERE id = 42;
```

## Frequently asked questions

**Which is more important, consistency or availability?**

It depends on the data. Bank balances and inventory counts usually need consistency, while social feeds, view counts, and shopping carts can tolerate brief staleness in exchange for staying available.

**Does the CAP theorem apply to a single-server database?**

Not really. CAP applies to data replicated across multiple networked nodes; a single server has no partition between copies to worry about, although it can still simply go down.

**What is eventual consistency?**

Eventual consistency means that if no new updates are made, all copies of the data will eventually become identical. It is the typical guarantee of AP systems, which stay available during partitions and reconcile differences afterward.

## Sources

- [Eric Brewer: CAP Twelve Years Later: How the "Rules" Have Changed](https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
