Consistency Models

Problem framing

Distributed systems replicate state for availability and scale, but replication introduces divergence. Consistency models define what clients can assume about reads relative to writes. Without explicit guarantees, applications become brittle and correctness bugs are hard to reproduce.

Core idea / pattern

Strong consistency

Strong consistency (often linearizability) ensures reads reflect the latest successful write in a single global order. This model simplifies reasoning but requires coordination and can reduce availability under partition.

Causal consistency

Causal consistency preserves the order of causally related writes, but allows concurrent writes to be observed in different orders. It enables low-latency reads while respecting causal relationships such as read-your-writes and session guarantees.

Eventual consistency

Eventual consistency allows replicas to diverge temporarily, but guarantees convergence when updates stop. Applications must handle conflicts or use mergeable data types to reconcile divergent histories.

Model Guarantee Typical cost
Strong Global order, latest reads Higher latency, lower availability
Causal Preserves causality Metadata overhead, session tracking
Eventual Convergence over time Conflicts, app-level reconciliation

Architecture diagram

sequenceDiagram
  participant Client
  participant Leader
  participant Replica1
  participant Replica2
  Client->>Leader: Write(x=1)
  Leader->>Replica1: Replicate x=1
  Leader->>Replica2: Replicate x=1
  Client->>Replica2: Read x
  Replica2-->>Client: x=1
        

Animated flow

Leader Replica 1 Replica 2 Client

Step-by-step flow

  1. A client writes a value to the leader or primary replica.
  2. The leader replicates the write to followers and tracks acknowledgements.
  3. A read is routed to a replica based on the configured consistency level.
  4. If strong consistency is required, the system waits for quorum or leader confirmation.
  5. If eventual consistency is allowed, the read may return stale data.

Playground: Quorum consistency budget

Failure modes

Trade-offs

Real-world usage

Standard Resources