Course contents

08. Distributed Systems Lesson 4 of 10

Strong Consistency

See what linearizability promises, why follower reads break it, how leader reads, synchronous replication and majority quorums restore it, and what each costs.

17 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Linearizability: the system behaves like a single copy; after a write completes, every later read from anyone sees it.
  • Asynchronous follower reads are fast but can miss confirmed writes, so they are not linearizable.
  • Reading from the leader is linearizable only if the leader verifies it is still the leader.
  • Waiting for every replica ties write latency and availability to the worst replica; majority quorums tolerate a slow or failed minority.
  • Strong consistency costs coordination on every operation: use it for locks, uniqueness, balances and other check-then-act logic.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

“Strong consistency” is used loosely, but its precise form for a single object (a key, a register, a row) is linearizability (Herlihy and Wing, 1990): every operation appears to take effect atomically at some instant between its invocation and its response, and that order agrees with real time. Practically:

  • Once a write has completed, every read that starts afterwards, from any client, returns that value or a newer one.
  • Once any read has returned a value, no later read returns an older one.
  • Operations that overlap in time may be ordered either way.

It is what CAP calls “C”. For multi-object transactions the analogous guarantee is strict serializability (serializable plus real-time order; Spanner calls it external consistency).

Why it exists

Code written for a single database assumes one copy: check a balance then debit it, insert a username that must be unique, acquire a lock, elect a leader. With replicas, a read can hit a copy that has not yet seen a confirmed write, and those checks silently become wrong. Linearizability lets you keep writing code as if there were one copy, even though there are many.

How it works

Single leader, leader reads. All writes and reads go to one node, which orders them. Simple, linearizable as long as there is exactly one leader. The catch is the word exactly: after a partition, a deposed leader may not know it was replaced. Protocols handle it in two ways:

  • ReadIndex (Raft): before answering, the leader records its commit index and confirms with a heartbeat round that a majority still accepts it as leader. One round trip per read (batchable).
  • Leader leases: followers promise not to elect a new leader for a lease period; the leader serves reads locally while its lease is valid. No round trip, but correctness depends on bounded clock drift and pauses.

Synchronous replication to followers. The leader confirms a write only after followers have applied it, so a confirmed write is present everywhere. Follower reads then never miss a confirmed write. Strictly, there is still a window while a write is in flight where one follower shows it and another does not, so a client could see the new value and then the old one; fully linearizable designs close that with quorum reads or reads through the leader. Waiting for every follower also means one slow follower slows every write and one dead follower blocks writes.

Majority quorums (consensus). Raft, Multi-Paxos and Zab commit a write when a majority of nodes has persisted it, and elect leaders by majority vote. Any two majorities intersect, so a new leader always has every committed entry, and a read that consults a majority (directly, or via a leader that proved its leadership) sees the latest commit. With 2f + 1 nodes the system tolerates f failures; latency is set by the fastest majority, not the slowest node. etcd, ZooKeeper, Consul, CockroachDB, TiKV and Spanner (Paxos plus TrueTime) work this way.

Leaderless quorums. Dynamo-style stores with N replicas, writing to W and reading from R with R + W > N, make reads overlap the latest write. On their own they are not linearizable: concurrent writes, sloppy quorums, partial write failures and missing read repair can all produce anomalies. Treat “quorum” there as “usually fresh”, not as linearizable.

The cost. Each linearizable write needs a round trip to a majority; each linearizable read needs either the same or a lease. Across regions that is tens to hundreds of milliseconds per operation, and during a partition the minority side cannot serve.

When to use it

Where a stale read becomes a bug rather than a delay: distributed locks and leases, leader election, configuration and service metadata, uniqueness constraints (usernames, idempotency keys), account balances and inventory with hard limits, and any check-then-act sequence across clients. Coordination services (etcd, ZooKeeper) exist so you can keep this small, strongly consistent core separate from the bulk data.

When not to

Feeds, counters, analytics, recommendations, caches and most read-heavy content tolerate staleness. Paying a majority round trip for them wastes latency and capacity. Often a weaker guarantee covers the real requirement: “a user sees their own edits” is read-your-writes, not linearizability.

Trade-offs

Approach Reads Writes Tolerates
Leader reads with ReadIndex One majority round trip, leader capacity Majority round trip Minority failures
Leader reads with lease Local on leader Majority round trip Minority failures; assumes bounded clock drift
Sync to all followers, follower reads Local on any follower (small in-flight gap) Wait for slowest follower No failed follower without reconfiguration
Async followers Fast, not linearizable Fast Anything, but loses consistency

Alternatives

  • Sequential consistency: one global order respected by each client, but not tied to real time.
  • Causal consistency: causally related operations are seen in order; available during partitions.
  • Session guarantees: read-your-writes, monotonic reads, monotonic writes, writes-follow-reads; cheap and often enough for user-facing features.
  • Bounded staleness: reads at most t seconds behind, e.g. follower reads at a timestamp in distributed SQL databases.

Failure modes

  • Stale reads from a deposed leader when leadership is not re-verified or leases rely on clocks that jumped.
  • Lock without fencing: a client whose lock expired during a pause keeps writing; the storage must reject stale fencing tokens.
  • Even-sized clusters: 4 nodes tolerate only 1 failure, like 3, while adding a node to every quorum.
  • Cross-region quorum latency: placing a majority across continents makes every write pay intercontinental round trips.
  • Assuming “quorum” means linearizable in leaderless stores.

In production

Keep consensus groups at 3 or 5 members spread over failure domains so one zone loss leaves a majority. Use the database’s linearizable read mode explicitly where needed (for example, etcd’s default linearizable reads versus serializable reads, or reading from the leaseholder in CockroachDB). Monitor leader changes, commit latency and lease expiry. Use fencing tokens for anything protected by a lock. Measure the latency cost per operation and confine strong consistency to the data that needs it.

Common misconceptions

  • “Strong consistency means ACID.” ACID is about transactions on one database; linearizability is about replicas agreeing with real time.
  • “If replication is synchronous, every read is linearizable.” Not during in-flight writes, and not if a deposed node can still answer.
  • “Quorum reads are always linearizable.” Only with additional mechanisms; R + W > N alone is not enough.
  • “Strong consistency is too slow to use.” Within a region a majority round trip is typically a millisecond or two; the cost becomes dominant across regions.

Interview angle

Define linearizability with the timeline (“a read that starts after a write completes must see it”), then say how you would get it: a Raft or Paxos group, majority commits, leader reads with ReadIndex or leases. Explain the cost (a majority round trip per write, more across regions) and the availability consequence (the minority side stops during a partition). Then scope it: “I would use etcd for locks and leader election, and keep the user feed eventually consistent.”

Model assumptions

The simulated steps use a simplified model, not a benchmark. The app sends 120 requests per second (20% writes over 30 keys, Zipf 1) through a database proxy that sends writes to the leader and reads to the followers (or to the leader when the follower routes are removed). Each database has 8 connections, 30 ms reads and 10 ms writes. Followers apply each change about 50 ms after the leader (a 2 ms link plus a 50 ms replay delay; Follower 2’s link becomes 120 ms later on). Synchronous means the leader confirms once every follower has applied the write (10 ms of apply time each, on top of the replay delay) and its acknowledgement has travelled back; the leader keeps a connection busy meanwhile; in the majority step it confirms once one of the two followers has (leader plus one follower is 2 of 3), and reads go to the leader, standing in for ReadIndex or a lease (the leader's leadership check is not modelled). A stale read is a follower read that misses a write the leader already confirmed, which the lesson treats as a linearizability violation; the model does not check the in-flight window. The definition timeline and the deposed leader are scripted illustrations: the engine has no leader election, terms, ReadIndex or leases. Numbers show behaviour and orders of magnitude only.

How to read this demonstration.

  • Actual engine simulation: a leader with two followers: asynchronous follower reads that go stale, reads routed to the leader, synchronous replication with its latency (delay, apply, acknowledgement), a distant follower, and the 1-of-2 acknowledgement rule with a follower crash.
  • Scripted animation: the definition timeline and the deposed-leader step (traffic paused).
  • Hybrid demonstration: none.
  • Simplified model: one fixed leader; the stale-read counter counts follower reads that miss a write the leader already confirmed; it does not check the order of concurrent operations or the in-flight window, so it does not prove linearizability.
  • Time compression: slow motion (about 0.1 times real time).
  • Not supported by the simulation: Raft or any consensus protocol, leader election, terms, ReadIndex and leases, linearizability checking, network partitions.
The lesson as textEvery step of the simulation, written out.
  1. 1. A leader, two followers, fast answers

    The leader takes every write; two followers copy each write and serve the reads. Replication is asynchronous: the leader confirms a write at once, and the followers apply it about 50 ms later.

    The app sends about 120 requests a second, one in five a write. Everything succeeds and answers come back in a few tens of milliseconds. The question for this lesson: is every answer correct?

    Scene: The app writes through a proxy to the leader and reads from two followers, which apply changes about 50 ms after the leader. Requests succeed quickly.

    Key idea: Fast and error-free is not the same as consistent. Consistency is about which values reads may return.

  2. 2. Linearizable: behave like one copy

    Traffic is paused for a scripted timeline.

    Linearizability, the strongest single-object consistency model, means: every operation appears to take effect at one instant between its start and its end, as if there were a single copy. In practice: once a write has *completed*, every read that *starts afterwards*, from any client, returns that value or a newer one. (A read that overlaps the write may return either.)

    Watch: Alice sets x = 1; the leader confirms. *Then* Bob reads x, routed to Follower 1, which has not applied the change yet (the slow purple packet). Bob gets x = 0. His read started after the write completed, so this answer is not linearizable.

    Scene: Scripted: Alice’s write of x = 1 is confirmed by the leader. Afterwards Bob’s read goes to Follower 1, which has not yet applied the write, and returns x = 0: a linearizability violation.

    Key idea: Linearizable: after a write completes, every later read, from anyone, sees it.

  3. 3. Follower reads break the promise

    Back to live traffic. The stale reads tile counts follower reads that missed a write the leader had already confirmed: each one is a read like Bob’s, a linearizability violation. With followers 50 ms behind, that is a noticeable share of reads, concentrated on the most-written keys.

    Nothing is failing and latency looks great. Asynchronous follower reads are a perfectly good design for many features, but they are not strongly consistent, and no amount of speed changes that.

    Scene: With asynchronous replication, a share of follower reads miss writes the leader already confirmed. No errors, low latency.

    Key idea: Reading from asynchronous followers is fast but not linearizable: confirmed writes can be missing.

  4. 4. Read from the leader

    The simplest fix: send reads to the leader too. There is one up-to-date copy and everyone reads it, so a read that starts after a confirmed write always sees it. Stale reads: zero.

    The cost is capacity: the followers sit idle for reads and the leader now does all the work, several times busier than before. Read capacity no longer grows with more followers. Followers still matter, as copies to fail over to.

    Scene: All reads and writes go to the leader. There are no stale reads; the leader is several times busier and the followers serve no reads.

    Key idea: Single-leader reads are linearizable but put every read on one node.

  5. 5. Is the leader still the leader?

    Traffic is paused for a scripted illustration. Leader reads have a trap. Suppose the leader is cut off from the followers. They elect Follower 1 as the new leader (term 2), and it commits a write with Follower 2’s acknowledgement.

    The old leader does not know it has been replaced. A client that still reaches it asks for the value and gets the old one: stale again, from the “leader”.

    Real systems prevent this. Raft’s *ReadIndex* has the leader confirm with a majority (a heartbeat round) that it is still leader before answering a read. *Leader leases* skip that round trip by promising followers won’t elect anyone else for a few seconds, which is only safe if clocks are bounded.

    Scene: Scripted: Follower 1, now leader, commits x = 2 with Follower 2. A client then reads from the cut-off old leader and gets the old value x = 1.

    Key idea: A leader must prove it is still the leader (majority round or lease) before serving linearizable reads.

  6. 6. Make followers safe to read: wait for them

    Live traffic again, follower reads restored, and the leader now replicates synchronously: it confirms a write only after both followers have applied it. A read that starts after “saved” finds the write on any copy. Stale reads: zero, and reads are spread over the followers again.

    The cost moves to writes: each write waits for the slower follower (its 50 ms replay delay, its apply time and the acknowledgement’s way back, about 65 ms more), so P95 rises. (One gap remains: *while* a write is in flight, one follower may already show it and the other not. Fully linearizable systems close it with quorum reads or by reading through the leader.)

    Scene: With synchronous replication, follower reads have no stale results; writes wait about 65 ms longer for the followers, so P95 rises.

    Key idea: Synchronous replication makes confirmed writes visible everywhere, paid for in write latency.

  7. 7. Waiting for everyone means waiting for the slowest

    Follower 2 moves to a distant data centre, 120 ms away. Every write now waits for it, so write latency, and P95, jumps by more than 100 ms, although Follower 1 confirms within about 50 ms.

    Worse: if Follower 2 went down, waiting for *every* follower would block writes entirely (the database replication lesson shows that). Requiring all copies makes writes as slow as the slowest replica and as available as the least available one.

    Scene: Follower 2 is now 120 ms away. Synchronous writes wait for it, so P95 rises by more than 100 ms; there are still no stale reads.

    Key idea: Waiting for all replicas ties write latency and write availability to the worst replica.

  8. 8. Wait for a majority, not for everyone

    Consensus protocols such as Raft and Paxos commit a write once a majority has it. With three nodes, the leader plus Follower 1 is 2 of 3: the leader still sends every write to both followers, but confirms it as soon as one has applied it. Distant Follower 2 catches up later. Watch P95 fall back by more than 100 ms: one slow node no longer sets the pace.

    Reads must then overlap a majority too, or Follower 2 would serve stale data again. Here they go through the leader (real systems confirm leadership first, with ReadIndex or a lease, which the simulation does not model); reading a majority and taking the newest version also works. Any two majorities share at least one node, so a read always meets the latest committed write. Stale reads: zero.

    Three seconds in, Follower 2 crashes. Nothing happens: the leader and Follower 1 are still a majority, and writes keep succeeding. This is how etcd, ZooKeeper, Spanner and CockroachDB provide linearizable operations. The simulation does not run Raft or any consensus protocol: the leader is fixed (no election, no terms), and “majority commit” is a configured rule, confirm after one of the two followers acknowledged.

    Scene: Simulated: the leader sends every write to both followers and confirms it once Follower 1 has applied it, two of three; reads go to the leader. P95 falls by more than 100 ms and there are no stale reads. When Follower 2 crashes after three seconds, writes keep succeeding.

    Key idea: Majority quorums give linearizability while tolerating a minority of slow or failed nodes.

  9. 9. What strong consistency costs

    Linearizability makes a replicated system behave like one copy: no stale reads, no reads going backwards, no surprises for code written as if there were one database. It is what you want for locks, leader election, unique constraints, balances and anything checked-then-acted-on.

    It costs coordination: a round trip to a majority on writes (and on reads, unless a lease is used), the latency of the farthest node you must wait for, and unavailability for the minority side during a partition (CAP). Use it where a stale answer would be a bug, and weaker models elsewhere.

    Scene: Live traffic: writes commit once the leader and Follower 1 have them, distant Follower 2 catches up, and reads go through the leader. No stale reads and no errors.

    Key idea: Strong consistency = coordination on every operation. Pay it where stale answers are bugs.