Consistency Models

Before understanding consistency models, we need to answer a simple question:

What is consistency in distributed systems?

Consistency defines what value a user reads after someone writes data.

In a single-machine system, this is trivial:

But in distributed systems:

This creates a problem:

Two users may see different versions of the same data.

Consistency models define rules for how this behavior should work.


Why Consistency is Required

Without consistency rules:

Example

Imagine an e-commerce app:

This leads to:

Consistency models help define:


The Core Trade-off

There is no perfect system.

Stronger consistency = Higher latency + lower availability
Weaker consistency = Better performance + possible stale data


Types of Consistency


1. Strong Consistency

Strong consistency guarantees:

After a write completes, all future reads will return that value.

There is no ambiguity.


How It Works


Example

Banking system:

Anything else is unacceptable.


Characteristics


Databases


2. Eventual Consistency

Eventual consistency guarantees:

If no new updates happen, all nodes will eventually have the same value.

But not immediately.


How It Works


Example

Social media likes:


Characteristics


Databases


3. Causal Consistency

Causal consistency sits between strong and eventual.

It guarantees:

Related operations are seen in the correct order.


Example

Chat system:

  1. User sends: "Hello"
  2. User replies: "How are you?"

System must ensure:

But:


Characteristics


Visual Trade-off

graph LR
    SC[Strong Consistency] --> HL[High Latency]
    EC[Eventual Consistency] --> LL[Low Latency]

Real-World Analogy

Think of consistency like messaging:


When to Use Which

Use Strong Consistency When

Examples:


Use Eventual Consistency When

Examples:


Use Causal Consistency When

Examples:


Consistency in CAP Theorem

In CAP:

During partition:


Practical Insight

Modern systems are flexible:

Example:


Key Takeaways

Always choose based on business requirements, not defaults