CAP and PACELC
the theorem everyone quotes wrong, and the latency trade-off that matters on a normal day.
- address
- everything.scale.cap_and_pacelc
- part
- part 17, scale and distribution
- chapter
- chapter 6 of 10
- reading time
- 7 min
CAP: when the network splits a replicated system in two (a partition), each side must either keep answering, and risk answering with stale data (available), or refuse until it can be sure (consistent). you don't get to opt out of partitions, so the real choice is C or A during one. PACELC adds the other 99.9% of the time: else, with no partition, you trade latency against consistency on every request.
the picture
you know how CAP gets quoted as "pick two of consistency, availability and partition tolerance", as if you could pick C and A and skip P? that's the misquote. partitions aren't a feature you decline. they're something the network does to you.
think of two bank branches whose phone line goes dead. a customer at branch A deposits money; a customer at branch B asks for the balance. branch B can say "can't tell you right now" (consistent, not available) or read out the last balance it knows (available, maybe wrong). there's no third option while the line is dead. step through both:
two replicas of one value, x = 1. a client sits next to each.
what the letters mean
the theorem is precise, and the precise version is narrower than the slogan.
- C, consistency
- linearizability: every operation appears to happen at one instant between its start and its end, so once a write has completed, every later read returns it or something newer. not the C of ACID, which is about constraints.
- A, availability
- every request to a node that hasn't failed gets a non-error answer, eventually. not "five nines", and not "most requests".
- P, partition tolerance
- the system keeps going while the network drops arbitrary messages between nodes.
Eric Brewer stated it as a conjecture in his PODC 2000 keynote. Seth Gilbert and Nancy Lynch proved a formal version in 2002 ("Brewer's conjecture and the feasibility of consistent, available, partition-tolerant web services"): in an asynchronous network that can lose messages, no read/write register can guarantee both linearizability and availability. Brewer's own retrospective in 2012 ("CAP twelve years later") makes the same point this chapter does: the "two of three" phrasing misleads, because partitions are rare and the choice only bites while one is happening.
what the theorem doesn't say
it's easy to make CAP say more than it does:
- it's about one register under a partition, nothing more. it says nothing about latency, throughput, transactions or what happens without a partition.
- "consistent" means linearizable. a system that gives up linearizability can still give strong guarantees (causal consistency, read-your-writes) and stay available.
- "available" means every live node answers. a CP system usually stays up on the majority side of a partition; only the minority side refuses. most people would call that available.
- the choice can be made per operation. a system can be CP for account balances and AP for the "last seen" timestamp.
PACELC: the normal day
partitions are rare. what you pay every day is latency. Daniel Abadi's PACELC (IEEE Computer, 2012, "Consistency Tradeoffs in Modern Distributed Database System Design") puts it in one line: if there's a Partition, choose A or C; Else, choose Latency or Consistency. keeping replicas consistent means waiting for them before you answer, and waiting is latency, partition or not.
- · async streaming replica serving reads
- · dynamo-style stores: dynamo, cassandra, riak
- · primary with a synchronous standby: commits wait
- · consensus systems: the minority side stops
- · synchronous_commit = local, async standbys
- · reading from any replica
- · synchronous_commit = remote_apply
- · fully consistent systems such as VoltDB
postgres makes this concrete. a primary with an asynchronous standby is EL: COMMIT returns as soon as the primary's own WAL is flushed, and the standby catches up later (which is why read-your-writes needs care). a synchronous standby moves it toward EC: every commit waits for the standby, and with remote_apply, for the standby to replay. that wait is a network round trip on every commit:
hover a stage.
and during a partition, that synchronous standby is the PC choice: if it can't be reached, commits on the primary wait rather than succeed unreplicated. the manual describes exactly this, and the usual remedy is several standbys with a quorum (ANY 1 (s1, s2)), so one lost standby doesn't stop the primary. streaming replication has the settings.
keylines
- partitions aren't optional, so CAP is a choice made during one: answer, or be sure.
- C is linearizability. A is every live node answering.
- the theorem is about one register under a partition, nothing more.
- PACELC: else, with no partition, you still trade latency for consistency.
- in postgres: async replicas lean EL/PA, synchronous standbys lean EC/PC.