Course contents

08. Distributed Systems Lesson 3 of 10

PACELC

CAP covers the rare partition. See the everyday trade-off instead: synchronous replication costs write latency, asynchronous replication costs stale reads.

14 minAdvanced7 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • PACELC: if there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency.
  • The else-branch applies in normal operation, so for most systems it matters more than the partition branch.
  • Synchronous replication keeps replicas consistent but makes each write wait for the slowest or farthest replica.
  • Asynchronous replication keeps writes fast but leaves a window in which replicas miss confirmed writes.
  • Distance raises both prices; most systems let you choose per table, per request or per region.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

PACELC is Daniel Abadi’s extension of CAP (blog post 2010, IEEE Computer article 2012). It reads as a sentence:

If there is a Partition, choose between Availability and Consistency; Else (normal operation), choose between Latency and Consistency.

A system is described by two choices, for example PA/EL (available during partitions, low latency otherwise) or PC/EC (consistent in both cases).

Why it exists

CAP is often over-applied. It only constrains a system during a partition, which is a rare event, and it says nothing about the cost of consistency on an ordinary day. Yet many designs that “chose availability” did so for latency, not partitions: as soon as data is replicated, keeping the copies in agreement before answering requires communication, and communication takes time. PACELC names that everyday trade-off.

How it works

Why the else-branch exists. A write that must be visible on every replica before it is confirmed has to reach them (and, in real protocols, be acknowledged). That costs at least one round trip to the replicas you wait for. Consensus protocols wait for a majority, which is the fastest majority but still a round trip. Answering without waiting is fast but means replicas temporarily miss a confirmed write.

The two knobs.

  • Synchronous (or quorum) replication: confirm after the replicas (or a majority) have the write. Reads on those replicas see it. Write latency includes the round trip to the slowest replica you wait for.
  • Asynchronous replication: confirm after the local write, replicate afterwards. Writes are as fast as one node allows; replicas lag by at least the one-way trip plus apply time, and reads there can be stale.

Distance is the price list. Light in optical fibre travels at about 200,000 km/s, roughly 200 km per millisecond, and real routes are longer than straight lines. Within one availability zone a round trip is well under a millisecond; between zones of a region, typically a millisecond or two; between continents, tens to well over a hundred milliseconds. Moving a replica farther away increases the latency of waiting for it and the staleness of not waiting.

Middle grounds.

  • Semi-synchronous replication: wait for one replica (usually a nearby one) and replicate to the rest asynchronously.
  • Quorums: wait for W of N replicas on write and read R of N, with R + W > N so reads overlap the latest write (with caveats covered in the strong-consistency lesson).
  • Per-operation consistency: Cassandra-style consistency levels, MongoDB read and write concerns, DynamoDB’s choice between eventually and strongly consistent reads, follower reads with a bounded staleness in some distributed SQL databases.
  • Home regions: keep each record’s authoritative copy in one region (near its users), with synchronous replication inside the region and asynchronous copies elsewhere.

Classifying systems. Abadi’s 2012 examples: Dynamo, Cassandra and Riak (default settings) are PA/EL; VoltDB/H-Store, Megastore and BigTable/HBase are PC/EC; MongoDB (at the time) PA/EC; Yahoo’s PNUTS PC/EL. These describe defaults; configuration often moves a system to another quadrant, so describe the configuration, not the product.

When to use it

Use PACELC whenever you place replicas or choose a replication mode: deciding whether a standby is synchronous, whether reads may go to followers, how far apart regions are, which consistency level each query uses. It is particularly useful in multi-region designs, where the else-branch costs tens of milliseconds per write.

When not to

For a single-node database, or replicas used only for failover that never serve reads and accept the risk of losing the last few writes, the latency/consistency question mostly reduces to durability on failover. PACELC also does not replace thinking about specific consistency models: “C” here is a family (linearizable, sequential, causal...), not a single setting.

Trade-offs

Configuration Normal operation During a partition Typical use
Async replicas, read anywhere (PA/EL) Fast writes, stale reads Stays available, diverges Feeds, catalogues, analytics
Sync or quorum replication, leader reads (PC/EC) Slower writes, consistent reads Minority side unavailable Payments, inventory, metadata
Sync within a region, async across regions Local-speed consistent writes; remote readers lag Per region Most multi-region OLTP
Per-request consistency levels Pay only where needed Per request Mixed workloads

Alternatives

  • CAP alone: enough to reason about failure behaviour, silent on everyday cost.
  • Consistency-model hierarchies (linearizable → sequential → causal → session guarantees → eventual) give finer choices than “C or L”.
  • Bounded staleness (“at most 10 s or 100 versions behind”) turns the else-branch into a tunable number.

Failure modes

  • Synchronous replica becomes the latency floor. A slow or distant synchronous replica slows every write; a dead one can block writes unless the system drops it from the synchronous set.
  • Invisible staleness. Async lag does not show up in latency or error dashboards; it surfaces as user-visible bugs (“I saved it and it is gone”).
  • Lost writes on failover. Promoting an async replica loses the writes it had not received.
  • Accidental cross-region chatter. A “local” read that has to consult a leader in another region quietly adds a cross-continent round trip.

In production

Measure replication lag per replica and alert on it. Keep synchronous replicas close (same region, different zones) and remote ones asynchronous. Route reads that must see the user’s own writes to the leader or to a replica known to be caught up (pass the write’s log position or a timestamp). Set consistency levels per query rather than globally, and document which operations need which. Load-test with realistic inter-region latency, not a local network.

Common misconceptions

  • “We don’t have partitions, so CAP doesn’t affect us.” The latency/consistency trade-off affects you every day.
  • “Async replication is free.” It costs staleness and possible data loss on failover.
  • “Faster hardware removes the cost of synchronous replication.” The round trip dominates; disks and CPUs don’t shorten it.
  • “A system has one PACELC label.” Configuration and per-request settings move it between quadrants.

Interview angle

After stating CAP, add: “and in normal operation, PACELC: latency versus consistency.” Then put numbers on it: a cross-region synchronous write costs at least one round trip (say 70–150 ms intercontinental), so you keep synchronous replicas within a region and replicate asynchronously across regions, routing read-your-writes traffic to the home region. Naming per-operation consistency levels shows you know real systems are not one quadrant.

Model assumptions

The simulation is a simplified model, not a benchmark. Region 1’s app sends 80 requests per second (30% writes over 50 keys, Zipf 1) through a database proxy that sends writes to the primary and reads to a local replica (2 ms away); Region 2 sends 60 reads per second to Replica 2, 60 ms away (150 ms in later steps). Each database has 16 connections, 5 ms reads and 8 ms writes. Synchronous means the primary confirms once every replica has applied the write (8 ms) and its acknowledgement has travelled back, so a write waits for the farthest replica's full round trip, and keeps its primary connection while it waits. This is not a network-partition model: the "partition" step blocks replication by delaying it by ten minutes (the link is not cut and the nodes stay up); the primary gives up waiting after 2.5 s and the clients after 2 s. Real databases differ (PostgreSQL waits for the standby, MySQL semi-sync falls back to async after a timeout). Stale reads are replica reads that miss a write the primary already confirmed. Clients give up after 2 s. Numbers show behaviour and orders of magnitude only.

How to read this demonstration.

  • Actual engine simulation: asynchronous and synchronous replication across distances (60, 150 and 25 ms), write latency including the acknowledgement's way back, stale reads in Region 2, client timeouts, and the blocked-replication step.
  • Scripted animation: none: every step is simulated.
  • Hybrid demonstration: none.
  • Simplified model: fixed distances and apply times; staleness is a read that misses a write the primary already confirmed; 'partition' means replication is blocked by a delay, no link is cut.
  • Time compression: slow motion (about 0.1 times real time); the ten-minute replication delay outlasts the step.
  • Not supported by the simulation: network partitions as such, consensus or quorum systems, per-operation consistency levels, read-your-writes routing.
The lesson as textEvery step of the simulation, written out.
  1. 1. Most of the time, nothing is partitioned

    CAP only speaks about partitions, and partitions are rare. This lesson is about the other 99.9% of the time.

    The primary in Region 1 takes every write; Replica 1 next to it serves Region 1’s reads; Replica 2, 60 ms away in Region 2, serves Region 2. Replication is asynchronous: the primary confirms a write after storing it locally and ships it afterwards.

    Writes are fast: P95 about 20 ms. Every request succeeds.

    Scene: Region 1’s app writes to the primary and reads from Replica 1; Region 2 reads from Replica 2, 60 ms away. Replication is asynchronous, writes take about 20 ms at P95 and nothing fails.

    Key idea: CAP covers the rare partition. The everyday question is what replication costs when the network is fine.

  2. 2. Else: fast writes, stale reads

    Nothing is broken, yet Region 2 regularly reads old data. Each write needs at least 60 ms to reach Replica 2; any Region 2 read of that key during that window misses a write the primary has already confirmed. The stale-reads tile counts them: a few percent of Region 2’s reads, concentrated on the hot keys.

    That is the E in PACELC: *Else* (no partition), choose Latency or Consistency. Asynchronous replication chose latency.

    Scene: With asynchronous replication and no failure, Replica 2 lags about 60 ms behind and a few percent of Region 2’s reads are stale. Writes stay fast.

    Key idea: Even without a partition, replication forces a choice: confirm fast and let replicas lag, or wait and stay consistent.

  3. 3. Else: consistent reads, slower writes

    Switch the primary to synchronous replication: it confirms a write only after both replicas have applied it. Any read that starts after “saved” now finds the write on either replica. Stale reads drop to zero.

    The bill arrives in latency. Each write waits for the farthest replica, so write latency rises by a full round trip to Region 2 (the change travels there, is applied, and the acknowledgement travels back) and P95 goes from about 20 ms to about 150 ms. Reads are as fast as before.

    Scene: With synchronous replication there are no stale reads, but every write waits for Replica 2, 60 ms away, and P95 rises to about 150 ms.

    Key idea: Synchronous replication buys consistency with write latency, set by the slowest or farthest replica.

  4. 4. Distance sets the price

    Region 2 moves to another continent: the link now takes 150 ms. Nothing else changes.

    Every synchronous write now waits about 300 ms longer than it would with no replica (150 ms each way), and P95 climbs past 300 ms. No configuration fixes that: light in fibre covers roughly 200 km per millisecond, and the trip is set by geography.

    That is why globally consistent databases either accept this latency on writes or keep each record’s authoritative copy in one region and replicate elsewhere asynchronously.

    Scene: Replica 2 is now 150 ms away. With synchronous replication every write waits for it and P95 rises above 300 ms; there are still no stale reads.

    Key idea: The latency cost of consistency is set by physics: the distance to the replicas you must wait for.

  5. 5. P: the partition question is CAP again

    One second in, replication to the replicas stops getting through. How this is simulated: the engine does not cut the network; every replication change is delayed by ten minutes, so none arrives during the step. The primary is still synchronous, so it cannot confirm anything: writes time out after 2 s. Reads keep working, and none is stale.

    This is the P-A-C half of PACELC: if there is a Partition, choose Availability or Consistency. This setup chooses C. With asynchronous replication it would have kept accepting writes and served increasingly stale reads, as in the CAP lesson.

    So this configuration is PC/EC: consistent during partitions and in normal operation, paying with errors in the first case and latency in the second.

    Scene: Replication stops getting through one second in. The synchronous primary cannot confirm writes, so writes time out after 2 seconds; reads still succeed and none is stale.

    Key idea: PACELC = if Partition: Availability or Consistency; Else: Latency or Consistency.

  6. 6. Choosing latency at 150 ms

    The link is healthy again, and the team switches back to asynchronous replication to get fast writes. P95 drops back to about 20 ms.

    But distance also widens the stale window: changes now take at least 150 ms to reach Region 2, so a larger share of Region 2’s reads are stale than at 60 ms. Moving a replica farther away raises the price of *both* choices: more latency if you wait, more staleness if you don’t.

    This configuration is PA/EL: available during partitions, low latency otherwise, and consistent only eventually.

    Scene: With asynchronous replication and Replica 2 150 ms away, writes are fast again (P95 about 20 ms) but a larger share of Region 2’s reads are stale than at 60 ms.

    Key idea: Distance raises both prices: the latency of waiting and the staleness of not waiting.

  7. 7. Four letters, two questions

    Daniel Abadi’s PACELC (2010, published 2012) extends CAP: if Partition, Availability or Consistency; Else, Latency or Consistency. The second question applies all the time, so it usually matters more.

    Abadi’s examples: Dynamo, Cassandra and Riak in their default settings are PA/EL; VoltDB/H-Store, Megastore and BigTable/HBase are PC/EC; MongoDB (as of 2012) PA/EC; Yahoo’s PNUTS PC/EL. Treat labels as defaults: most systems let you move per table or per request (consistency levels, read concerns, follower reads, synchronous standbys).

    The recipe: decide per operation what a stale read costs, then pay for consistency only where that cost is higher than the latency.

    Scene: The final setup: asynchronous replication to a local replica and to Replica 2, 150 ms away. Writes are fast and Region 2 reads are sometimes stale.

    Key idea: Name both halves: what the system does during a partition, and what it trades when there is none.