Distributed Systems: Consistency Models

高级
最后更新:2026年01月16日 03:13
创建于:2026年01月16日

Understanding different consistency models in distributed systems

distributed-systems consistency cap-theorem

Distributed Systems: Consistency Models

The CAP Theorem

In distributed systems, you can only have 2 of 3: - Consistency: All nodes see the same data - Availability: Every request gets a response - Partition Tolerance: System works despite network partitions

Consistency Models (Strongest to Weakest)

1. Linearizability (Strongest)

  • Operations appear to execute atomically
  • Real-time ordering respected
  • Example: Single-server systems

2. Sequential Consistency

  • Operations appear in some total order
  • Each process's operations appear in program order
  • Example: Most traditional databases

3. Causal Consistency

  • Causally related operations ordered
  • Concurrent operations may be seen in different orders
  • Example: Version vectors, vector clocks

4. Eventual Consistency (Weakest)

  • All replicas eventually converge
  • No ordering guarantees
  • Example: DNS, CDNs

Practical Considerations

Model Latency Availability Use Case
Linearizable High Low Financial transactions
Sequential Medium Medium User sessions
Causal Low High Social feeds
Eventual Lowest Highest Caching, CDN

Implementation Patterns

Quorum Systems

N = Total replicas
W = Write quorum
R = Read quorum

Strong consistency: W + R > N
Example: N=3, W=2, R=2

Vector Clocks

Track causality across nodes:

Node A: {A:1, B:0}
Node B: {A:0, B:1}
After sync: {A:1, B:1}

Real-World Examples

  • Spanner: Linearizable (TrueTime)
  • DynamoDB: Eventually consistent (default)
  • CockroachDB: Serializable
  • Cassandra: Tunable consistency

笔记信息

难度级别:高级
创建时间:2026年01月16日
最后更新:2026年01月16日 03:13