CAP theorem
The CAP theorem, also known as Brewer's theorem, states that in a distributed system subject to network partitions, it is impossible to simultaneously guarantee all three of the following properties: consistency (C), availability (A), and partition tolerance (P).[1] Introduced as a conjecture by computer scientist Eric Brewer during a 2000 talk at the ACM Symposium on Principles of Distributed Computing (PODC), the theorem highlights fundamental trade-offs in designing distributed data stores and web services, where systems must prioritize two properties at the expense of the third in the presence of communication failures.[2] Formally proven in 2002 by Seth Gilbert and Nancy Lynch, the theorem applies specifically to asynchronous network models, demonstrating through contradiction that no algorithm can ensure both atomic consistency and availability when messages may be lost between system components.[1] Consistency refers to the requirement that all reads from the system reflect the most recent write or a subsequent write, providing a linearizable view as if operations occur on a single node, while availability ensures that every request to a non-failing node receives a timely response, even under load or failure.[1] Partition tolerance, in turn, mandates that the system continues to operate correctly despite arbitrary network partitions, which isolate groups of nodes and prevent communication between them—a common reality in large-scale distributed environments like the internet.[2] These properties are not binary but exist on a spectrum; for instance, systems may offer tunable consistency levels, such as eventual consistency, to balance trade-offs.[3] The theorem's implications have profoundly influenced the architecture of modern distributed systems, including NoSQL databases, cloud services, and microservices, encouraging designers to explicitly manage partitions rather than assuming their rarity. However, the theorem has faced criticism, notably from Martin Kleppmann in 2015, for oversimplifying trade-offs in real-world systems.[4] Brewer's later reflections in 2012 refined the understanding, emphasizing that while partitions are infrequent, systems should aim to maximize both consistency and availability during normal operation, using techniques like version vectors, conflict-free replicated data types (CRDTs), and recovery protocols to handle rare failures gracefully. Examples of CAP trade-offs include CP systems like Google's Chubby lock service, which prioritize consistency and partition tolerance over availability, and AP systems like Dynamo, which favor availability and partition tolerance with relaxed consistency.[3] Overall, the CAP theorem underscores the safety-liveness dichotomy in distributed computing, guiding engineers to align system guarantees with application needs in unreliable networks.[1]Core Concepts
Theorem Statement
The CAP theorem states that in a distributed computer system, it is impossible to simultaneously guarantee all three of the following properties: consistency (C), availability (A), and partition tolerance (P).[5] Specifically, the theorem asserts: "It is impossible in the asynchronous network model to implement a read/write object that guarantees the following properties: (i) waiting for writes to be propagated to a quorum of replicas before acknowledging, (ii) all reads and writes eventually complete, and (iii) the object continues to function despite an arbitrary number of messages being dropped by the network."[5] This impossibility arises because network partitions—temporary failures in communication between nodes—are inevitable in large-scale distributed environments, such as those spanning multiple data centers or geographic regions.[2] During such partitions, the system must choose between prioritizing consistency (ensuring all nodes see the same data) or availability (ensuring every request receives a response), as maintaining both would require instantaneous and reliable message delivery across the partition, which cannot be assured.[5] The underlying reason all three properties cannot coexist stems from the asynchronous nature of network communication in distributed systems, where messages can be delayed, lost, or reordered indefinitely without violating the model assumptions.[5] This forces a binary trade-off under partitions: systems can be CP (consistent but potentially unavailable) or AP (available but potentially inconsistent), while partition tolerance (P) is non-negotiable in realistic settings.[2] To illustrate the trade-off, consider the CAP triangle, a conceptual model depicting C, A, and P as vertices of a triangle, with network partitions acting as an external force that collapses the structure, compelling designers to select two properties at the expense of the third:This diagram highlights that while CP or AP combinations are feasible, achieving CAP fully is not.[2] (Detailed definitions of C, A, and P are provided in subsequent sections.)C ────────── A ╱ ╲ ╱ ╲ P (Partition forces choice between C and A)C ────────── A ╱ ╲ ╱ ╲ P (Partition forces choice between C and A)