Skip to content
Rabin Poudyal
Rabin Poudyal
← All models

Software and engineering

The CAP theorem

During a network partition each operation must give up either availability or consistency; the rest of the time the trade is latency against consistency.

Eric Brewer, PODC keynote, 19 July 2000; proved in the asynchronous model by Seth Gilbert and Nancy Lynch (2002); reframed by Brewer in "CAP Twelve Years Later" (2012).

CAP stands for consistency, availability and partition tolerance. Brewer's keynote at the 2000 Principles of Distributed Computing conference (PODC) set consistency against availability under network partitions, with slides for forfeiting each of the three and a contrast between ACID databases (atomic, consistent, isolated, durable) and what he called BASE, basically available, soft state, eventually consistent. Gilbert and Lynch made it a theorem in 2002: with consistency defined as atomic (linearisable) reads and writes, availability as every request to a working node getting a response, and partitions as arbitrary message loss, no system in the asynchronous model can give all three. The useful reading is not 'pick two'. Partitions are not chosen, they happen, so the real choice is what each operation does while one is in progress.

Brewer said as much in 2012: the 'two of three' framing was always misleading. Partitions are rare, and when there is none a system can be both consistent and available. During a partition the choice can be made per operation, per data item, even per user, rather than once for the whole system. He proposes three steps: detect the partition, enter a partition mode that limits which operations proceed, and on recovery restore consistency and compensate for the mistakes made meanwhile. His example is a cash machine that allows withdrawals up to a limit while cut off from the bank, then reconciles. GitHub's 2018 incident shows the choice being made twice: availability by the failover tool during a 43-second partition, then consistency by the engineers for the next 24 hours.

Martin Kleppmann's 2015 critique argues that the formal theorem is narrow and its words are slippery. CAP's consistency means linearisability only, and CAP's availability is not the availability in a service agreement, so many real systems are neither C nor A in CAP's sense and the theorem says nothing about them. It is often read as proof that eventually consistent databases are more available than strongly consistent ones, which he shows needs more careful reasoning. He proposes thinking in terms of delay sensitivity instead: how each operation's latency responds to network delay. Gilbert and Lynch's own 2012 retrospective places CAP inside the older trade-off between safety and liveness. Use it as a reminder to design for partitions, not as a taxonomy of databases.

Example

On 21 October 2018 routine maintenance cut connectivity between GitHub's US East Coast network hub and its primary data centre for 43 seconds. Orchestrator, the tool that manages MySQL failover, saw the West Coast cluster form a quorum and promoted it to primary, keeping the databases available for writes. When the link came back the East Coast held writes from those 43 seconds that the West Coast lacked, while the West Coast had taken on more than 30 minutes of new writes before the situation was clear; one busy cluster had 954 writes in the affected window. GitHub then chose consistency over availability: rather than discard either side, it ran degraded for 24 hours and 11 minutes while it restored and reconciled, pausing webhooks and Pages builds to protect user data.

Where it applies

Decide per operation what happens during a partition: adding to a cart can proceed and reconcile, capturing a payment must wait. For an agent or RAG (retrieval-augmented generation) system with a replicated vector store or memory, decide whether a stale read is acceptable (usually yes) and whether a duplicated write is (usually no), and test it by cutting the network rather than by reading the database's marketing page.

Think about it

If the link between your two regions dropped for a minute right now, which of your writes would be accepted on both sides, and how would you reconcile them?

Applied it to something real? Log it.

Test yourselfWhy does Brewer say the 'pick two of three' reading of CAP is misleading?

Partitions are rare, so most of the time a system can be both consistent and available. The trade-off only has to be made while a partition exists, and it can be made per operation rather than once for the whole system.

Related models

Sources and further reading