CAP Theorem and PACELC in Practice
Navigate the reality of network partitions, master the trade-offs between availability and consistency, and apply the PACELC theorem to real databases.
Every engineer who designs distributed systems encounters the CAP theorem. Proposed by Eric Brewer in 2000, it states a fundamental physical boundary: in a distributed data store, you cannot simultaneously achieve Consistency, Availability, and Partition Tolerance.
However, the CAP theorem is widely misunderstood. Many developers mistakenly believe they can "choose CA" and ignore network partitions. In reality, physical networks always experience partitions. Your only real choice during a partition is between Consistency and Availability.
Furthermore, network partitions are rare. The PACELC theorem extends CAP to explain the trade-offs systems must make during the 99.9% of time when the network is operating normally.
01Deconstructing the CAP Properties
To apply CAP effectively, you must understand the rigorous definitions of its three core terms:
- Consistency (Linearizability): Every read receives the most recent write or an error. The system behaves as if there is only a single, atomic copy of the data item in existence, even if replicated across multiple continents.
- Availability: Every non-failing node must return a non-error response for every received request. It does not guarantee that the response contains the latest written data, but it guarantees the service never returns an HTTP 500 or times out.
- Partition Tolerance: The system continues to operate despite an arbitrary number of messages being dropped, delayed, or partitioned by the physical network between nodes.
Why "CA" Does Not Exist in Distributed Systems
In an ideal world without network cables, switches, or cloud hypervisors, a system could be both fully Consistent and fully Available.
However, physical networks are inherently unreliable. Fiber optic cables get severed by backhoes, switch firmware crashes, and cloud routers drop packets under load.
Because network partitions (P) are an unavoidable physical reality, you cannot choose CA. When a partition inevitably occurs, you must choose either:
- CP (Consistency over Availability): Cancel or reject the operation, returning an error to preserve strict consistency.
- AP (Availability over Consistency): Accept the operation on whichever node is reachable, returning potentially stale data and resolving conflicts later.
Loading the rest of the lesson…