Sub topic 7
Consistency Models and the CAP/PACELC Trade-offs
This chapter assumes you know what replication is and why each key lives on N nodes. It also assumes you can read short Python snippets. Here you learn what "consistent" can mean for a key-value store and which trade-offs follow from it.
What a consistency model promises
A consistency model is a contract about what a read may return after writes. Replicas receive updates at different times, so a read can hit a replica that has not seen the latest write. The model says which results are allowed.
| Model | Promise | Typical cost |
|---|---|---|
| Linearizable (strong) | Every operation appears to take effect at one instant, in real-time order | Coordination on every operation |
| Sequential | All clients see the same order, but it need not match real time | Still needs global agreement |
| Causal | Writes that are causally related are seen in order by everyone | Track dependencies, such as vector clocks |
| Eventual | If writes stop, all replicas converge to the same value | Reads can be stale or conflicting |
A leaderless store such as the one this tutorial builds usually offers eventual or causal-style behavior by default. Quorums can tighten it, but the next chapter shows that they do not give linearizability on their own.
CAP: what happens during a partition
A network partition is a failure that splits nodes into groups that cannot talk to each other. The CAP theorem says that during a partition a replicated store must choose one of two behaviors:
- Consistency (C): refuse requests that cannot be answered correctly. Some clients get errors or timeouts.
- Availability (A): answer every request from whatever replicas are reachable. Answers may be stale, and both sides may accept conflicting writes.
Partitions are not optional in a real network, so the choice is really between C and A when one occurs. CAP says nothing about normal operation.
PACELC: the cost when nothing is broken
CAP is silent about the common case, so Daniel Abadi proposed PACELC. It reads: if there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency.
The "else" half matters most day to day. Even with a healthy network, a strongly consistent read or write must wait for several replicas, possibly in other data centers. A weaker setting returns after fewer replies and is faster.
| System style | Partition (PAC) | Normal (ELC) | Label |
|---|---|---|---|
| Dynamo-style, leaderless, low quorums | Availability | Latency | PA/EL |
| Consensus-based, such as Raft-replicated | Consistency | Consistency | PC/EC |
Real systems let you tune this per request, so treat the labels as defaults.
Common mistakes
- Calling a store "CP" or "AP" as a fixed label. Settings such as quorum sizes move it along a spectrum.
- Assuming eventual consistency means "wrong." It means replicas converge, and you decide how stale a read may be.
- Assuming "strong consistency" is free. It costs latency every time, not only during failures.
Exercise
A store has a healthy network. A client asks for the strongest read the store offers, and the read is slower than a weaker read. Which part of PACELC explains this, and why does CAP not?
Show answer
The "Else, Latency versus Consistency" part explains it. A strong read waits for more replicas to respond, which takes longer even without failures. CAP only describes behavior during a partition, so it says nothing about this normal-operation cost.
Exercise
During a partition, a store accepts writes to the same key on both sides. Which CAP choice is this, and what must the store do after the partition heals?
Show answer
It chose availability. After healing, it must detect that the writes were concurrent, for example with vector clocks, and resolve them with a strategy such as last-write-wins, keeping siblings, or a CRDT.