Linearizability

The guarantee that a replicated system behaves as if there were one copy of the data: what it promises, when you need it, how systems provide it, and what it costs.

Overview

Replication keeps several copies of the same data. Clients would like to ignore that and treat the system as if it held a single copy. Linearizability is the promise that makes this possible: every read and write appears to happen at one instant, and that instant falls between the moment the operation starts and the moment it returns.

Behave like one copy

Maurice Herlihy and Jeannette Wing defined linearizability in 1990. Jepsen's summary is a good working definition: every operation appears to take effect atomically, in some order that matches real time. If operation A finishes before operation B starts, B must see the effect of A.

The practical rule for a single value is simple. Once any read has returned a new value, no later read, by any client on any replica, may return the old one. Here is a history that breaks the rule, with a leader and a follower that lags behind it.

  • On the leader, x was just set to 2. It used to be 1.
  • Alice reads x from the leader and gets 2.
  • Alice's read has finished. Only then does Bob start his read, and he sends it to the lagging follower.
  • The follower returns 1, a stale value.

Returning 1 to Bob would go back in time, because his read started after Alice's ended and she had already seen 2. A linearizable system cannot do it.

Without linearizability, Bob could see a score, a stock level or a lock owner that Alice has already seen replaced. With it, both behave as if they had talked to one machine.

Key concepts

  • Linearizability
  • Recency guarantee
  • Serializability
  • Strict serializability
  • Sequential consistency
  • CAP theorem
  • Lightweight transaction

Interview questions

  • What is linearizability, in one or two sentences?
  • When do you actually need linearizability?
  • What is the difference between linearizability and serializability?
  • Are quorum reads and writes (W + R > N) linearizable?
  • How do etcd and ZooKeeper differ on read consistency?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio