This note provides a summary of PACELC, a framework for understanding the tradeoff between consistency and latency in distributed systems.
Table of Contents:
In case you're unfamiliar, the CAP theorem states that any distributed data store can provide only two of the following three guarantees:
Consistency
"Consistency, informally, simply means that each server returns the right response to each request, i.e., a response that is correct according to the desired service specification. (There may, of course, be multiple possible correct responses.) The meaning of consistency depends on the service." [1]
Availability
"Availability simply means that each request eventually receive a response. Obviously, a fast response is better than a slow response, but for the purpose of CAP, it turns out that even requiring an eventual response is sufficient to create problems. (In most real systems, of course, a response that is sufficiently late is just as bad as a response that never occurs.)" [1]
Partition tolerance
"The third requirement of the CAP theorem is that the service be partition tolerant. Unlike the other two requirements, this property can be seen as a statement regarding the underlying system: communication among the servers is not reliable, and the servers may be partitioned into multiple groups that cannot communicate with each other. For our purposes, we simply treat communication as faulty: messages may be delayed and, sometimes, lost forever. (Again, it is worth pointing out that a message that is delayed for sufficiently long may as well be considered lost, at least in the context of practical systems.)" [1]
Proof sketch : Consider an execution in which the servers are partitioned into two disjoint sets: {p1
} and {p2
, . . . , pn
}. Some client sends a read request to server p2
. Since p1
is in a different component of the partition from p2
, every message from p1 to p2
is lost. Thus, it is impossible for p2
to distinguish the following two cases:
v1
requested of p1
, and p1
has sent an ok response.v2
requested of p1
, and p1
has sent an ok response.No matter how long p2
waits, it cannot distinguish these two cases, and hence it cannot determine whether to return response v1
or response v2
. It has the choice to either eventually return a response (and risk returning the wrong response) or to never return a response. [1]
The CAP tells us that we can't pick all three from Consistency, Availability, and Partition Tolerance. Therefore, only CA systems (consistent and highly available, but not partition-tolerant), CP systems (consistent and partitiontolerant, but not highly available), and AP systems (highly available and partition-tolerant, but not consistent) are possible.
But it is not the partition tolerance that necessitates a tradeoff between consistency and availability; rather, it is the combination of
The theorem simply states that a network partition causes the system to have to decide between reducing availability or consistency. But in reality, network partitions are highly dependent on the details of your system implementation. Is it using highly redundant machines? Are the machines largely dispersed? Is it a local cluster? Designing your system based on chosing two out of three of the CAP properties is misleading as in typical distributed system you will ideally not be experiencing a partition often. Therefore it's better to think through what properties should your system have in the event of a partition and in the event of normal operation with no partition.
Every component in a system is prone to eventual failure of some sort, whether it's hardware or software based it does not matter as cosmic rays will treat your system the same. Thus if we want our system to have high availability, that necessitates data replication so that we can handle multiple components going offline yet still be responsive to requests. The mere risk of failure dictates the need for ongoing data replication to meet availability requirements.
Introducing data replication in a distributed system immediately creates a tradeoff between consistency and latency. To understand why, we can think through all of the ways data can be updated: synchronized across all replicas simultaneously, sent to a designated master node, or directed first to a randomly chosen node. Each method has its own implications for balancing consistency with latency.
Case 1: Data updates sent to all replicas at the same time:
Case 2: Data updates sent to an agreed-upon location first:
If the system routes all reads to the master node and serves them from there, then there is no reduction in consistency. However, there are two latency problems with this approach:
If reads can be done from anywhere then read latency is better but write latency is still potentially far away. This can also result in inconsistent reads of the same data item, as different locations have different versions of a data item while the system is still propagating updates, and it could send a read to any of these locations.
Asynchronous case is a bit more complicated
Case 3: Data updates sent to an arbitrary location first
The system performs updates at that location, and then propagates them to the other replicas. The difference between this case and case 2 is that the location the system sends updates to for a particular data item is not always the same. For example, two different updates for a particular data item can be initiated at two different locations simultaneously. The consistency/latency tradeoff again depends on two options:
A more complete portrayal of the space of potential consistency tradeoffs for distributed systems can be achieved by rewriting CAP as PACELC (pronounced “pass-elk”):
Learn More →
Note that the latency/consistency tradeoff (ELC) only applies to systems that replicate data. Otherwise, the system suffers from availability issues upon any type of failure or overloaded node. Because such issues are just instances of extreme latency, the latency part of the ELC tradeoff can incorporate the choice of whether or not to replicate data.
Popular databases like Dynamo, Cassandra, and Riak operate as PA/EL systems by default: if a partition occurs, they give up consistency for availability, and under normal operation they give up consistency for lower latency. Giving up both Cs in PACELC makes the design simpler; once a system is configured to handle inconsistencies, it makes sense to give up consistency for both availability and lower latency.
Below is a list of examples from the original paper that outlines which parts of the CAP + PACELC tradeoff space various distribted database systems inhabit:
System | CAP Classification | PACELC Classification | Use Case | Justification |
---|---|---|---|---|
Dynamo, Cassandra, and Riak | AP | PA/EL | E-commerce, social media, big data | Prioritizes transaction completion over consistency; user settings can alter trade-offs. |
PNUTS | CP/CA | PC/EL | Global data distribution for low-latency access | Prioritizes consistency, even increasing it during network partitions. |
MongoDB | CP/AP | PA/EC | Wide range of applications requiring fast development and schema flexibility | Balances availability and consistency; adapts to conditions by electing a new master during partitions. |
VoltDB/H-Store | CP | PC/EC | Financial services, telecommunications, real-time analytics | Focuses on strong consistency and high performance, sacrificing availability and latency if necessary. |
Dynamo, Cassandra, and Riak:
PNUTS:
MongoDB:
VoltDB/H-Store:
[1] : https://groups.csail.mit.edu/tds/papers/Gilbert/Brewer2.pdf