Understanding Consistency Models in Distributed Systems
When building distributed systems, data is often replicated across nodes. Consistency models define how updates to that data become visible to clients. Here are the most common models, from strict to relaxed:
-
Strong Consistency (Linearizability)
- All clients see the most recent write immediately.
- Reads always return the latest value.
- Simplifies reasoning but can sacrifice availability and latency.
-
Sequential Consistency
- All operations from every client appear in some total order.
- Each client observes its own operations in program order.
- Weaker than linearizability because real-time order may differ.
-
Causal Consistency
- Writes that are causally related must be seen in the same order by all processes.
- Concurrent, unrelated writes may be observed in different orders.
- Preserves cause-and-effect relationships, useful for collaborative apps.
-
Read-After-Write (Immediate) Consistency
- After a successful write, subsequent reads from the same client see the new value.
- Other clients may see the old value until the write propagates.
-
Monotonic Read Consistency
- Once a client has seen a particular value, it will never see an older value.
- Important when clients migrate between replicas.
-
Monotonic Write Consistency
- Writes from a single client are serialized in the order issued.
- Prevents older writes from overwriting newer ones during reconnection.
-
Session Consistency
- A client gets monotonic reads and read-after-write guarantees within a session.
- Useful for applications that maintain user sessions.
-
Bounded Staleness
- Reads may lag behind writes by a known time window or number of versions.
- Provides a predictable staleness bound while allowing faster reads.
-
Eventual Consistency
- In the absence of new updates, all replicas converge to the same value.
- Offers high availability and partition tolerance at the cost of temporary staleness.
-
Strong Eventual Consistency (SEC)
- A stronger form of eventual consistency where replicas that have received the same updates always converge without requiring coordination.
- Used in CRDT-based systems.
Choosing the Right Model
Selecting a consistency model involves trade-offs between availability, latency, and the complexity of your application logic. Critical financial transactions often require strong guarantees, while social media feeds can tolerate eventual consistency for better performance.
Understanding these models helps you design systems that balance correctness with real-world constraints like network partitions and replication lag.