PACELC & CONSISTENCY MODELS

Even with no partition, you pay latency for consistency

L215 MINDISTRIBUTED SYSTEMS
PREDICT

Eventual mode: the store acks a write as soon as R1 has applied it, and R2 applies writes 50 ms after R1. The client writes x=7 to R1, gets the ack at t=2 ms, and reads x from R2 at t=27 ms. What does it see?

CAP only talks about partitions. PACELC finishes the sentence: if Partitioned, choose Availability or Consistency; Else, choose Latency or Consistency. The second half is the one you pay every day.

With three replicas, a linearizable store acknowledges a write only after a majority has applied it, and reads from a majority. Every read sees every acknowledged write, every write waits for the second-fastest replica to apply it, and every read waits for the second-nearest to answer. Quorum overlap alone only guarantees that a read sees writes that completed before it began; full linearizability also needs the reader to write back what it saw before answering (the ABD algorithm), or reads that go through a leader. An eventual store acknowledges after the local apply and reads the nearest replica. Both are fast, and a read can miss a write you were already told succeeded.

▶ SIMULATION
REPLICA R1
x = 0 (ver 0)
idle
REPLICA R2
x = 0 (ver 0)
idle
REPLICA R3 (slow)
x = 0 (ver 0)
idle
modeeventual
write—
last read—
t = 0 msx = 0 on R1, R2, R3. The client is next to R1 and R2.
✓ a read after an acknowledged write returns that write or newer
SCHEDULE
01[System]System: mode eventual (ack after the local apply, read the nearest replica)
02[Client]Client → R1: write x=7
03[Client]Client: 25 ms pass (think time)
04[Client]Client → R2: read x (nearest replica)
05[Network]Network: replication reaches R2, R2 applies x=7
06[Client]Client → R2: read x again
07[Network]Network: replication reaches R3, R3 applies x=7
Start of eventual scenario. 7 steps.
PACELC (Abadi, 2012):

  if Partitioned:  trade Availability against Consistency      (CAP)
  Else:            trade Latency      against Consistency

Where the latency goes, for a write to 3 replicas that apply it after 0 / d / 2d:

  linearizable   ack after a majority applies    write latency = d
                 read asks a majority            read latency  = round trip to
                                                 the 2nd-nearest replica
                 every read sees every acknowledged write

  eventual       ack after the local apply       write latency = local
                 read asks one replica           read latency  = local
                 a read may return a value older than one you were told was written

  in between     read-your-writes / session: route reads to a replica that has
                 your write, or carry its version and wait for it. Cheap, but
                 only for your own writes, only while the session holds.

Watch the invariant strip and the latency numbers. EVENTUAL acks in 2 ms and the read from R2 comes back stale. LINEARIZABLE never goes stale, and pays for it: the write waits 50 ms for R2 to apply it. The quorum read costs only 2 ms, because R1 and R2 are both next to the client; R2 is behind, not far away. READ-YOUR-WRITES stays fresh only because it reads from R1.

TUNE IT NOT YET

Keep the schedule: write at t=0, acknowledged at t=2, read from R2 at t=27. Drag REPLICA DELAY to the lowest value at which that read comes back stale.

GOAL: the read at t=27 is stale at this delay and fresh one notch lower

FIX IT NOT YET

Implement write and read for both modes. Linearizable: acknowledge only after a majority has applied, and read from a majority so the two quorums overlap. Eventual: acknowledge after the first apply. In both, report the latency you actually waited. Replicas come in no fixed order, and how far away a replica is (delayMs) is not how far behind it is. The grader checks the values, the quorum sizes and the honesty of every latency.

Mental model:

consistency is a waiting policy. A stronger model makes each request wait for more replicas, so the slowest replica you must hear from sets your latency. Linearizable means write and read majorities overlap; eventual means an ack only promises that one replica has it. Partitions are rare; this trade happens on every request.

IN PRODUCTION

Read replicas behind a primary, DynamoDB and Cassandra consistency levels (eventually consistent reads, QUORUM, LOCAL_ONE), MongoDB read and write concerns, and any CDN or cache in front of a database. The symptom: a user cannot see their own change for a moment.

IN INTERVIEWS

“Explain PACELC” or “Why do I sometimes read my own write as missing?” Name the latency you pay for a majority, explain why read and write quorums must overlap (R + W > N) and why overlap alone is not linearizable without read write-back or leader reads, and offer read-your-writes as the cheaper middle ground when only a user's own writes matter.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: IDEMPOTENCY & EXACTLY-ONCE →