Consistency Models

A consistency model is a contract between a distributed system and its clients, specifying what values reads can return given the history of writes — defining how “up to date” and “ordered” observations of shared data can be.

Problem

In a distributed system with replicated data, different nodes may hold different versions of the same data at any given moment. The consistency model answers: if client A writes a value, when and how will client B see it? Without a defined model, application developers cannot reason about correctness.

The Consistency Spectrum

Consistency models form a hierarchy from strongest (most guarantees, highest cost) to weakest (fewer guarantees, lower cost):

Linearizability (Strict Consistency)
    │ ↓ weaker
Sequential Consistency
    │ ↓ weaker
Causal Consistency
    │ ↓ weaker
FIFO / PRAM Consistency
    │ ↓ weaker
Eventual Consistency

Data-Centric Models (System-Wide Guarantees)

Linearizability (Strong Consistency)

  • Every read returns the most recent write; operations appear to execute atomically at a single point in time
  • Equivalent to a single-copy system — the gold standard
  • Cost: high coordination; Raft/Paxos quorum required for every operation
  • Examples: etcd, Zookeeper, Google Spanner, CockroachDB

Sequential Consistency

  • All operations appear in the same global order to all processes, but that order doesn’t have to match real time
  • Weaker than linearizability: write order is consistent across all readers, but reads may lag real time
  • Used in: multi-core CPU memory models (within a core)

Causal Consistency

  • Operations that are causally related appear in the same order to all processes; concurrent operations may appear in different orders
  • A writes X, then reads Y=5 and writes Y=6 — B must see X before Y=6
  • Examples: MongoDB causal sessions, some distributed databases with vector clocks

FIFO / PRAM Consistency

  • Each process’s writes are seen by other processes in the order they were issued (FIFO per process)
  • No guarantee about ordering between different processes’ writes
  • Weaker than causal; doesn’t require tracking causal dependencies

Eventual Consistency

  • If no new writes occur, all replicas will eventually converge to the same value
  • No guarantee about when convergence happens or what readers see in the interim
  • Examples: Cassandra, DynamoDB (default), DNS, CouchDB

Client-Centric Models (Per-Client Guarantees)

These guarantee consistency from the perspective of a single client’s session, rather than system-wide.

GuaranteeDescription
Read-Your-Writes (RYW)Client always reads its own most recent write
Monotonic ReadsClient never sees data older than what it already read
Monotonic WritesClient’s writes are applied in the order issued
Writes-Follow-ReadsA write that follows a read is applied after all values the read returned

These four together are called Session Guarantees — see Session Guarantees for details.

Conflict Resolution

When concurrent writes occur to the same key across replicas:

StrategyHowTrade-off
Last-Write-Wins (LWW)Timestamp determines winnerSimple; can lose writes
Vector ClocksCausality graph detects concurrent writesAccurate; complex; vectors grow
CRDTsMerge-friendly data structures (counters, sets)Automatic; limited data types

Real-World Database Mapping

DatabaseConsistency ModelNotes
Google SpannerLinearizabilityTrueTime API for global time
CockroachDBSerializable (linearizable reads)Raft-based
etcdLinearizabilityRaft quorum
CassandraTunable (eventual by default)Quorum reads/writes = strong
DynamoDBEventual by defaultStrong consistency option
MongoDBCausal sessionsTunable to majority
RedisEventual (async replication)Strong option with WAIT

Trade-offs

Stronger ModelWeaker Model
More predictable for developersFewer coordination costs
Prevents anomalies (lost writes, stale reads)Better latency and availability
Requires consensus protocolsSimpler replication
Higher operational costPossible data anomalies