{
  "id": "cap-theorem",
  "title": "CAP Theorem",
  "lang": "en",
  "source_lang": "en",
  "summary": "The CAP theorem states that a distributed data system cannot guarantee both linearizable consistency and availability when network partitions occur.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "Brewer’s theorem",
    "Consistency–availability–partition tolerance theorem"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/cap-theorem/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/cap-theorem/",
      "json": "https://aiwiki.page/zh/cap-theorem.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The CAP theorem is an impossibility result in distributed computing: a distributed data system cannot guarantee both consistency and availability in every execution that may include a network partition. Here, consistency means that operations behave as if performed on a single, up-to-date copy of the data; availability means that every request received by a non-failing node eventually completes. The theorem explains a fundamental limitation of replicated databases and other shared-data services, rather than prescribing a particular system architecture."
    },
    {
      "heading": "The three properties",
      "text": "The acronym CAP stands for consistency, availability, and partition tolerance. These terms have narrower meanings in the theorem than they often have in product descriptions.\n\nConsistency\n\nCAP consistency is normally formalized as linearizability, also called atomic consistency. Each operation must appear to take effect instantaneously at some point between its invocation and completion, and the resulting order must respect the real-time order of non-overlapping operations.\n\nFor a read/write register, this means:\n\n- A read returns the value of the latest preceding write in that order.\n- If a write completes before a read begins, the read cannot return an older value unless another write intervenes.\n- Concurrent operations may be ordered either way, provided the complete history remains valid.\n\nThis is stronger and more precise than saying that replicas “eventually agree” or contain identical data at every physical instant. Replicas may temporarily differ internally while the service still presents a linearizable interface.\n\nCAP consistency is not the same as the consistency in ACID properties. ACID consistency concerns preserving application-defined database invariants through transactions. Linearizability instead concerns the externally observable ordering of operations. Nor does CAP by itself specify the isolation level of a database transaction.\n\nAvailability\n\nAvailability means that every request received by a non-failing node must eventually receive a response that completes the requested operation according to the service’s specification.\n\nA node cannot preserve CAP availability merely by immediately returning “service unavailable” whenever coordination is impossible. Likewise, an indefinitely blocked request violates availability even if the process remains running.\n\nThe formal property does not impose a particular response-time limit. A request may take an arbitrarily long but finite time to finish. This differs from operational availability, commonly measured as uptime, successful-request percentages, or latency targets in a service-level agreement.\n\nPartition tolerance\n\nA network partition prevents some groups of nodes from communicating with others, even though nodes on both sides may remain operational and reachable by clients. Communication within each group may continue normally.\n\nThe theorem’s model permits communication failures that can prevent messages from arriving indefinitely. Under those conditions, a system cannot rely on every node eventually hearing from every other node.\n\nPartition tolerance is therefore not simply a feature that an implementation can switch off while retaining the same failure assumptions. A system may assume partitions never occur, but its consistency and availability guarantees then do not cover executions in which that assumption fails."
    },
    {
      "heading": "Why consistency and availability conflict",
      "text": "Consider two nodes, \\(A\\) and \\(B\\), each storing a replica of a register initially containing \\(0\\).\n\n- A network partition blocks all communication between \\(A\\) and \\(B\\).\n- A client asks \\(A\\) to write \\(1\\).\n- To remain available, \\(A\\) must eventually complete the write without waiting indefinitely for \\(B\\).\n- After the write has completed, another client asks \\(B\\) to read the register.\n- To remain available, \\(B\\) must eventually answer despite being unable to communicate with \\(A\\).\n\nLinearizability requires the read to return \\(1\\), because the write completed before the read began. But \\(B\\) has received no information about the write. From its perspective, this execution is indistinguishable from one in which no write occurred, where the correct answer would be \\(0\\).\n\nNo algorithm can guarantee the correct answer in both cases using the same local information. Waiting for communication sacrifices availability; answering without the necessary information can sacrifice consistency.\n\nThis indistinguishability argument is the core of the impossibility result. The problem is not insufficient processing power, storage, or implementation quality: a node cannot reliably act on information it cannot obtain."
    },
    {
      "heading": "History",
      "text": "Eric Brewer presented the CAP conjecture in a keynote at the 2000 ACM Symposium on Principles of Distributed Computing. It expressed a trade-off observed in the design of large networked services.\n\nIn 2002, Seth Gilbert and Nancy Lynch published a formal statement and proof for an asynchronous distributed-system model. Their formulation made the relevant meanings of consistency, availability, and communication failure explicit.\n\nBrewer later emphasized that the common slogan “choose any two” oversimplifies the result. The unavoidable choice between consistency and availability arises during a partition; it need not describe all operations or all periods of a system’s lifetime."
    },
    {
      "heading": "Interpreting “choose two”",
      "text": "CAP is often illustrated as a triangle with three possible combinations. This can be useful shorthand, but the combinations require qualification.\n\nLabel | Typical meaning | Important qualification\nCP | Preserve consistency despite partitions | Some requests may block or fail during a partition.\nAP | Preserve availability despite partitions | Operations may produce histories that are not linearizable.\nCA | Provide consistency and availability under a no-partition assumption | Both guarantees cannot be maintained across arbitrary partitions affecting the service.\n\nA CP system does not necessarily stop everywhere during a partition. A connected majority may continue processing requests while an isolated minority refuses operations that require coordination. The system nevertheless lacks CAP availability because requests at some non-failing nodes cannot complete.\n\nAn AP system need not return arbitrary or useless results. It may offer precise weaker guarantees, retain local ordering, or support only operations that can safely proceed independently. What it cannot guarantee is unrestricted availability together with linearizability for the shared data under the theorem’s assumptions.\n\nCA is not a way for a partitioned replicated service to escape the theorem. It usually describes a system whose guarantees depend on communication remaining intact or whose scope excludes independently serving replicas."
    },
    {
      "heading": "Consequences for system design",
      "text": "Replication, leaders, and quorums\n\nData replication improves resilience and can reduce read latency, but creates a need to coordinate updates and observations.\n\nA leader-based system may route writes through one node and acknowledge them only after enough replicas have recorded them. During a partition, only the component satisfying the coordination rules may continue serving strongly consistent operations.\n\nA quorum requires participation from a specified subset of replicas, often a majority. Intersecting quorums help prevent isolated groups from independently committing incompatible histories. However, quorum arithmetic alone does not establish linearizability: correctness also depends on version ordering, leader changes, read procedures, and failure handling.\n\nProtocols for consensus, such as Raft and Paxos, help replicas agree on an ordered sequence of decisions. They do not evade CAP. Implementations that preserve safety during partitions may lose the ability to complete operations when the required communication is unavailable.\n\nWeaker consistency and reconciliation\n\nSystems that continue accepting operations on disconnected replicas need rules for handling divergent state after communication resumes. Possibilities include retaining conflicting versions, applying application-specific merge rules, or using conflict-free replicated data types for suitably structured operations.\n\nEventual consistency generally means that replicas converge if updates cease and the required communication and repair continue. It does not imply that every read immediately sees the latest completed write.\n\nRelaxing linearizability does not by itself provide a complete design. A service must still specify which values reads may return, how concurrent writes interact, and what happens to acknowledged operations during reconciliation.\n\nOperation-specific choices\n\nA single service can make different choices for different operations. For example, it might allow reads of cached data while refusing updates that require coordination, or offer both strongly consistent and weaker read modes.\n\nSuch a service needs to define its guarantees at the appropriate scope. A successful stale read does not satisfy a request for a linearizable read, and availability of one operation does not establish availability of every operation."
    },
    {
      "heading": "Related results and practical limits",
      "text": "CAP and latency\n\nCAP availability is an eventual-completion property, not a guarantee of low latency. A service may remain formally available while responding too slowly for practical use. Conversely, a highly available production service may deliberately reject requests in rare partition scenarios and therefore not satisfy formal CAP availability.\n\nThe PACELC formulation highlights a broader design trade-off: if a partition occurs, a system faces an availability–consistency choice; else, during ordinary operation, it may face a latency–consistency trade-off. Synchronous cross-region coordination, for example, incurs communication delay even when the network is healthy. PACELC complements CAP rather than replacing its impossibility result.\n\nCAP and consensus impossibility\n\nThe FLP impossibility result addresses guaranteed termination of deterministic consensus in a fully asynchronous system with even one possible process crash. CAP addresses the incompatibility of linearizable shared-data behavior and availability when communication partitions are permitted.\n\nBoth concern limits imposed by communication uncertainty, but their tasks, assumptions, and conclusions differ. A result about consensus termination should not be treated as interchangeable with CAP.\n\nWhat CAP does not establish\n\nCAP does not rank databases, determine acceptable business behavior, or show that every application must choose between all forms of correctness and all forms of availability. Its conclusion depends on specific definitions and a failure model.\n\nIn particular, it does not directly establish guarantees about transaction isolation, durability, data loss, or application invariants. Nor does it quantify how frequently partitions occur or how long they last. Systems described as “CP” or “AP” can differ substantially in their recovery procedures, consistency modes, handling of acknowledged writes, and behavior under failures beyond network partitions.\n\nAssessing an implementation therefore requires examining its actual operations and failure behavior, not only its CAP label."
    }
  ],
  "links": [
    "distributed-computing",
    "database",
    "acid-properties",
    "database-transaction",
    "service-level-agreement",
    "algorithm",
    "data-replication",
    "eventual-consistency"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}