Sub topic 6
PACELC: latency versus consistency when there is no partition
This chapter assumes you know what linearizability and eventual consistency mean, and that you have read the CAP chapter. You should also be comfortable with replication and with reading short Python programs.
CAP describes what a system must give up while the network is partitioned. Partitions are rare. Most of the time every replica can reach every other replica, and the system still has to pick a trade-off. PACELC names that second trade-off.
The statement
Daniel Abadi proposed PACELC in 2010 as an extension of CAP. It reads as a sentence:
- Partition: if there is a partition, choose between Availability and Consistency.
- Else: when the system runs normally, choose between Latency and Consistency.
The first half restates CAP. The second half is the new part: even with a healthy network, a replicated system cannot be both as fast as possible and as consistent as possible.
PACELC is a classification, not a theorem like CAP. It does not prove anything new. It points at a cost that CAP's focus on failures hides.
Why latency and consistency conflict
Replicas sit in different machines, racks, or regions. Information travels at a finite speed, so a message between two data centers takes tens or hundreds of milliseconds. A system has two basic choices for each operation.
- Coordinate before replying. The replica waits for other replicas, or for a leader, so that every client sees one consistent order of operations. The client pays the round-trip time.
- Reply from local state. The replica answers at once and propagates the change in the background. The client sees low latency, but another replica may briefly hold a different value.
The second choice is where stale reads and conflicting writes come from. This is the same cost you saw in the eventual consistency chapter, now viewed as a latency choice instead of a failure choice.
A latency model
The program below models three regions with fixed round-trip times. A client in ap-south talks to a system whose leader is in us-east. It compares reads and writes at different consistency levels.
# Round-trip times in milliseconds between regions.
RTT = {
("us-east", "us-east"): 2,
("us-east", "eu-west"): 80,
("us-east", "ap-south"): 190,
("eu-west", "eu-west"): 2,
("eu-west", "ap-south"): 120,
("ap-south", "ap-south"): 2,
}
REGIONS = ["us-east", "eu-west", "ap-south"]
def rtt(a, b):
return RTT.get((a, b)) or RTT[(b, a)]
def read_latency(client, leader, strong):
"""A strong read goes to the leader. A weak read uses the local replica."""
return rtt(client, leader) if strong else rtt(client, client)
def write_latency(client, leader, acks_needed):
"""The client sends to the leader. The leader waits for acks_needed
replicas in total, counting itself."""
to_leader = rtt(client, leader)
followers = sorted(rtt(leader, r) for r in REGIONS if r != leader)
wait = followers[acks_needed - 2] if acks_needed > 1 else 0
return to_leader + wait
client, leader = "ap-south", "us-east"
print("weak read ", read_latency(client, leader, strong=False)) # 2
print("strong read ", read_latency(client, leader, strong=True)) # 190
print("write, 1 ack ", write_latency(client, leader, 1)) # 190
print("write, majority", write_latency(client, leader, 2)) # 270
print("write, all ", write_latency(client, leader, 3)) # 380The same data costs 2 ms or 190 ms to read depending on the guarantee you ask for. A write that waits for every replica costs twice as much as one that waits for none. No partition occurs anywhere in this model. The cost comes from distance and from waiting.
The four PACELC classes
Each system gets a label of the form P?/E?. The first letter pair describes behavior during a partition, the second pair describes normal operation.
| Class | During a partition | Normally | Typical shape |
|---|---|---|---|
| PA/EL | Stay available | Favor low latency | Leaderless stores with asynchronous replication |
| PA/EC | Stay available | Favor consistency | Leader-based, but allows reads or writes to continue on a minority side |
| PC/EL | Preserve consistency | Favor low latency | Strong rules during failure, relaxed rules otherwise |
| PC/EC | Preserve consistency | Favor consistency | Consensus-based, strongly consistent stores |
Systems are often placed in these classes by their default configuration:
- Dynamo-style stores such as Cassandra and Riak are usually called PA/EL. Their default reads and writes touch few replicas.
- Google Spanner and similar consensus-based databases are usually called PC/EC. They pay cross-region latency on every write.
- Yahoo's PNUTS is the standard example of PC/EL. It does fast local reads of possibly stale data, but gives up availability for writes when the partition hits the record's master.
- MongoDB with default settings is often described as PA/EC.
These labels are approximate. Many products let you choose per operation. Cassandra at QUORUM for both reads and writes behaves much more like the EC side than at ONE. Treat a label as a statement about defaults, not about a product forever.
The decision flow
The diagram shows where each half of PACELC applies for a single request.
Note that the left branch and the right branch resemble each other. In both, the "fast" option answers from local state and the "consistent" option coordinates first. The difference is that during a partition coordination can fail forever. In normal operation coordination only takes time.
Where quorums fit
Quorum settings are the main knob for the EL/EC choice. With N replicas, a write that waits for W acks and a read that contacts R replicas give you the overlap condition R + W > N. Larger R and W raise latency, because the operation waits for the slowest replica among those it needs. You can also tilt the cost.
- Set
R = 1andW = Nfor fast reads and slow writes. - Set
W = 1andR = Nfor fast writes and slow reads. - Set both to a majority for a balance.
This tuning is a PACELC choice made at a finer grain than a product label. Remember the caveat from the quorum chapter: overlap alone does not give linearizability.
What PACELC does not say
- It is not a reason to ignore partitions. The P half still governs your behavior in failures, which are the moments that hurt most.
- "EL" does not mean "inconsistent." An EL system returns stale or divergent data only for the window before replication catches up. For many workloads that window is milliseconds.
- "EC" does not mean "slow everywhere." A consensus system with replicas in one data center may add under a millisecond. The cost grows with distance, so geography matters more than the label.
- The two halves are independent. A system can be PC/EL. Its behavior under failure does not determine its behavior in normal operation.
- Latency has a tail. Waiting for a majority makes you wait for the median-slowest replica. Waiting for all makes you wait for the slowest one. One slow node can set your 99th percentile.
A practical checklist
When you evaluate a system, ask these questions about the else branch before you ask about partitions:
- Where does a read go? A leader, a quorum, or the nearest replica?
- How many replicas must acknowledge a write before the client hears success?
- Are replicas in one region or several? What is the round-trip time between them?
- Can the application choose a different level per operation?
- What does the p99 latency look like at each level, not just the average?
Exercise
Using the program above, a client in eu-west talks to a system with its leader in us-east and three replicas, one per region. What is the latency of a strong read, and of a write that waits for a majority (2 of 3 replicas, counting the leader)? Which PACELC letter does each choice represent compared with a local read and a write that needs 1 ack?
Show answer
A strong read goes to the leader, so it costs rtt(eu-west, us-east) = 80 ms. A majority write costs 80 ms to reach the leader plus the wait for the nearest follower. The leader's followers are eu-west at 80 ms and ap-south at 190 ms, so the nearest is 80 ms, giving 160 ms in total. A local read costs 2 ms and a write needing 1 ack costs 80 ms. The strong read and majority write choose C in the "Else" half. The local read and single-ack write choose L, and they pay for it with possible staleness or lost writes if the leader fails before replicating.
Exercise
A team says, "Our database is PC/EL, so it is always consistent during partitions and always fast otherwise." Name two things wrong with this reading.
Show answer
First, PC means the system gives up availability to keep consistency during a partition. It does not mean the data is "always consistent" in every other sense, and it still refuses or delays some requests. Second, EL means that in normal operation the system favors latency over consistency, so reads can be stale even with no failure. The statement mixes up the two halves. PACELC describes tendencies at design time, and a real system may offer per-operation settings that move it between classes.