What is CAP Theorem?
CAP theorem states that a distributed data system cannot simultaneously provide consistency, availability, and partition tolerance; it can only guarantee two of the three.
The CAP theorem, also called Brewer's theorem, was introduced by computer scientist Eric Brewer in 2000 as a conjecture about the fundamental trade-offs in distributed systems. It was formally proved by Seth Gilbert and Nancy Lynch in 2002. The theorem describes three properties: consistency, meaning every read receives the most recent write or an error; availability, meaning every request receives a non-error response, without guarantee that it contains the most recent write; and partition tolerance, meaning the system continues to operate despite arbitrary message loss or network failures between nodes. According to the theorem, a distributed system can achieve at most two of these three properties simultaneously.
When a network partition occurs, meaning messages between nodes are lost or delayed, the system must choose between maintaining consistency and maintaining availability. If it chooses consistency, it must reject requests that cannot be verified against the latest state, thereby sacrificing availability. If it chooses availability, it may respond with stale data, sacrificing consistency. In practice, network partitions are inevitable, so distributed systems are usually designed as either CP (consistent and partition tolerant) or AP (available and partition tolerant). A system that claims to be CA is only possible if partitions never happen, which is unrealistic in a real-world distributed network.
Many modern distributed databases and services are architected with explicit CAP trade-offs. For example, Apache HBase and ZooKeeper favor CP by refusing writes during a partition to ensure consistency. Apache Cassandra and Amazon DynamoDB favor AP by allowing writes and reads from any replica even if some replicas are unreachable, accepting eventual consistency. The CAP theorem continues to guide system design, though later work such as the PACELC theorem extended the model to include trade-offs even in the absence of partitions.
Key facts
- Proposed by Eric Brewer at the 2000 ACM Symposium on Principles of Distributed Computing.
- Formally proved by Gilbert and Lynch in 2002 (Journal of the ACM).
- Only two of consistency, availability, and partition tolerance can be achieved simultaneously.
- In practice, partition tolerance is mandatory, so the real choice is between consistency and availability.
- CAP does not address latency or performance trade-offs when no partition occurs (addressed by PACELC).
How it works in practice
Related terms
References
More in Databases
ACID
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties guaranteeing reliable database transaction processing, ensuring data integrity despite concurrent access or failures.
B-Tree Index
A B-Tree index is a self-balancing tree data structure that maintains sorted data for efficient insertion, deletion, and range queries in database systems.
BASE
BASE is a design philosophy for distributed databases that prioritizes availability and partition tolerance over immediate consistency, making it a looser alternative to ACID in NoSQL systems.
Connection Pool
A managed cache of database connections that applications reuse rather than opening and closing a connection for each query, reducing latency and server load.
Failover
Failover is the process of automatically or manually promoting a replica database to primary when the active node fails, ensuring continued availability.
Foreign Key
A column or set of columns in a database table whose values must match a primary key in another table, ensuring referential integrity between the two tables.
Hash Index
A data structure that maps keys to storage locations using a hash function, providing constant-time equality lookups but no ordered or range scans.
Materialized View
A database object that stores the precomputed result of a query as a table, refreshed periodically or on demand to improve read performance and reduce computational overhead.
NoSQL
NoSQL is a family of non-relational database systems designed for flexible schemas, horizontal scaling, and high-throughput data access that traditional SQL databases cannot easily provide.
Read Replica
A read replica is an asynchronously updated copy of a primary database instance used to offload and scale read-only query traffic without affecting the source database's write performance.