Sub topic 3
Consistency trade-offs: CAP, PACELC and consistency models
This chapter assumes you know basic cloud networking, how stateless services sit behind load balancers, and how a database stores and reads data. It explains why an active-active design forces you to choose how consistent your data is across regions.
Why replication forces a choice
In an active-active design, every region accepts writes. A write in one region reaches the others over a wide-area link. That link is slow, and it can fail. Two regions can also receive conflicting writes before either hears about the other. You cannot avoid these facts, so you must decide what the system does about them.
CAP in practical terms
The CAP theorem describes what a replicated system can promise when the network partitions. A partition is a period when regions cannot talk to each other.
- Consistency (C): every read sees the most recent write.
- Availability (A): every request to a working node gets a non-error response.
- Partition tolerance (P): the system keeps operating despite lost messages between nodes.
Cross-region links do fail, so you must tolerate partitions. The real choice is what to give up during one:
- A CP system refuses some requests, usually writes in the cut-off region, to avoid returning stale or conflicting data.
- An AP system keeps serving every request, and accepts that regions may disagree until the partition heals.
CAP says nothing about normal operation, when there is no partition. That gap is what PACELC fills.
PACELC: the cost in normal operation
PACELC reads: if there is a Partition, choose between Availability and Consistency. Else, choose between Latency and Consistency.
The second half matters most day to day. Making a write visible in every region before you confirm it means waiting for a round trip between regions, which can take 70 to 150 ms or more. Confirming after a local write is fast, but other regions serve stale data for a short time.
| Style | During a partition | Normally | Typical examples |
|---|---|---|---|
| PA/EL | Stays available | Low latency, eventual consistency | Dynamo-style stores, multi-region DynamoDB global tables |
| PC/EC | Rejects some requests | Higher latency, strong consistency | Spanner-style synchronous replication |
| PA/EC or PC/EL | Mixed | Mixed | Systems with tunable settings |
Consistency models
Consistency is a range, not a switch. These are the models you will meet, from strongest to weakest:
- Linearizable (strong): operations appear to happen one at a time in real-time order. Costs a cross-region round trip.
- Causal: if one write depends on another, everyone sees them in that order. Unrelated writes may appear in any order.
- Read-your-writes: a user always sees their own updates, even if others lag.
- Eventual: if writes stop, all regions converge to the same value. No promise about when.
Common errors
- Assuming one setting for everything. Choose per data type. A shopping cart can be eventual. An account balance usually needs stronger guarantees.
- Ignoring read-your-writes. A user updates a profile, the next request goes to a lagging region, and the old value reappears. Pin the session to a region or read from the writing region for a short time.
- Confusing replication with consistency. Replicated data is not necessarily consistent data. Asynchronous replication means a regional failure can lose acknowledged writes.
- Treating CAP as a label. Most systems are tunable. Look at what each operation does during a partition.
Exercise
A checkout service in an active-active design confirms orders after writing only to the local region. During a partition between regions, which side of CAP has it chosen, and what normal-operation trade-off does PACELC say it made?
Show answer
It chose availability (AP), because it keeps accepting writes while cut off from other regions. In normal operation it chose low latency over consistency (EL), because other regions see the order only after asynchronous replication.