Sub topic 6
PACELC: latency versus consistency when there is no partition
This chapter assumes you know what replication is, the difference between linearizability and eventual consistency, and the CAP theorem from the previous chapter. You should also be able to read short Python snippets.
The gap CAP leaves open
CAP describes only what happens during a network partition: a system must choose between consistency and availability. Partitions are rare. Most of the time the network works, and CAP says nothing about that time.
Yet replicated systems still face a trade-off when nothing is broken. To keep replicas consistent, a write must reach other replicas before it is acknowledged. That takes at least one network round trip, and across regions it can take 100 ms or more. Skipping the wait is faster, but replicas may then disagree.
Daniel Abadi proposed PACELC to name this second trade-off.
Reading the acronym
PACELC reads as a two-part sentence:
- If there is a Partition, choose between Availability and Consistency.
- Else, choose between Latency and Consistency.
So a system gets a label with two letters after each half, such as PA/EL or PC/EC.
| Label | During a partition | Otherwise | Typical example |
|---|---|---|---|
| PA/EL | Stays available | Favors low latency | Dynamo-style stores with R=1, W=1 |
| PC/EC | Stays consistent | Favors consistency | Consensus-based stores such as Spanner or etcd |
| PA/EC | Stays available | Favors consistency | Systems with tunable settings, depending on configuration |
| PC/EL | Stays consistent | Favors low latency | Rare, for example some primary-backup systems with asynchronous replication |
Classifications are approximate. Many systems let you tune each choice per request, so a label describes a default, not a fixed property.
Where the latency cost comes from
The "else" half is about how many replicas a write or read must wait for. The sequence below shows a synchronous write and an asynchronous one.
In the asynchronous case, a read from the follower right after the second ok can still return 1. That is a stale read, bought in exchange for lower write latency.
A rough latency model
The snippet below estimates write latency under the two policies, given round-trip times to each replica. Waiting for W acknowledgements costs as much as the W-th fastest replica, because the leader needs only that many replies.
def write_latency(rtts_ms, acks_needed):
"""Latency when the write must be acknowledged by `acks_needed` replicas.
rtts_ms: round-trip time to each replica (the local replica is 0).
"""
return sorted(rtts_ms)[acks_needed - 1]
# One local replica and two remote ones.
rtts = [0, 80, 150]
print(write_latency(rtts, 1)) # 0 (async, favors latency)
print(write_latency(rtts, 2)) # 80 (majority)
print(write_latency(rtts, 3)) # 150 (all replicas)Choosing a majority costs 80 ms here, and waiting for every replica costs 150 ms. This is the E-branch trade-off in numbers.
Common mistakes
- Treating PACELC as a replacement for CAP. It extends CAP with a second question.
- Assuming a system has one fixed label. Settings such as quorum sizes and read preferences move it.
- Ignoring that the E-branch applies on every request, while the P-branch applies only during failures. For many applications the latency trade-off is the one that shapes daily behavior.
Exercise
A store has three replicas with round-trip times of 0, 40 and 200 ms from the leader. Using the model above, how long does a write take if it must be acknowledged by a majority, and which PACELC choice does that represent in the "else" half?
Show answer
A majority of three is two acknowledgements, so the latency is the second smallest round-trip time, 40 ms. Waiting for a majority favors consistency over latency, which is the EC choice. Waiting only for the local replica (0 ms) would be the EL choice.