System Design Foundations

Consistency Models

A spectrum from strong (every read sees the latest write) to eventual (replicas converge with no bound on when) — with practical stops in between that most real systems actually rely on.
  • Strong (linearizable) consistency: reads always reflect the most recent acknowledged write, as if there were a single copy of the data — requires coordination, costs latency
  • Eventual consistency: replicas converge given enough time and no new writes, but offer no guarantee about when — cheap and highly available, but stale reads are possible
  • Causal consistency: preserves cause-and-effect ordering (a reply is never visible before the comment it replies to) without paying for full linearizability
  • Session guarantees — read-your-own-writes and monotonic reads — are a practical middle ground: a user never sees their own change disappear or time travel backward
  • Stronger consistency generally means higher write latency and reduced availability under partition (Cap Theorem) — the choice is a tradeoff, not a strictly-better option
The consistency spectrum
ModelGuaranteeCost
Strong / linearizableEvery read sees the latest writeHighest — coordination on every op
CausalCause precedes effect, alwaysModerate — needs dependency tracking
Read-your-writesYou always see your own recent writesLow — sticky routing or version tokens
EventualConverges given time, no ordering promisedLowest — no coordination needed
A stale read after a write, under eventual consistency
The write already succeeded from the user's point of view, but a read routed to a lagging replica still returns the old value
A minimal read-your-writes token
class VersionedSession {
    private volatile long lastWriteVersion = 0;

    long recordWrite(long versionFromPrimary) {
        lastWriteVersion = Math.max(lastWriteVersion, versionFromPrimary);
        return lastWriteVersion;
    }

    // Replica read waits (or retries) until its applied version >= lastWriteVersion.
    boolean replicaCanServe(long replicaAppliedVersion) {
        return replicaAppliedVersion >= lastWriteVersion;
    }
}
The client (or a session-aware proxy) tracks the version of its own last write and requires a replica to have caught up before reading from it
Sources
  • Designing Data-Intensive ApplicationsCh. 5 — Replication (Problems with Replication Lag)
  • System Design Interview – An Insider's Guide, Volume 2Ch. 1 — Consistency Patterns