Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Consistency Models

When everyone sees the same thing (or not)

Consistency answers a fundamental question: When you update data in one place, when do other parts of your system see that change?

Think of it like updating a shared document. Do you want everyone to see changes instantly (strong consistency), or is it okay if they see them a few seconds later (eventual consistency)?

Diagram

Consistency isn’t binary—it’s a spectrum from strongest to weakest:

Diagram

Understanding how major companies use different consistency models helps illustrate their practical importance:

The Challenge: Banks need to ensure account balances are always accurate. A user’s balance must be the same across all systems immediately after any transaction.

The Solution: Banks use strong consistency:

  • Account Balance: All systems see the same balance immediately
  • Transaction Processing: Locks ensure no double-spending
  • Critical: Money accuracy is more important than speed

Example: User transfers $100:

  • Strong Consistency: Lock Account A → Deduct $100 → Lock Account B → Add $100 → Unlock both
  • Result: Both accounts always show correct balance
  • Trade-off: Slower (waits for locks), but guaranteed accuracy

Impact: Zero incorrect balances. All transactions are accurate. Critical for financial systems.

Eventual Consistency: Social Media Platforms

Section titled “Eventual Consistency: Social Media Platforms”

The Challenge: Social media platforms need fast user experience. Like counts, comments, and posts need to update instantly, but perfect accuracy across all data centers isn’t critical.

The Solution: Social media platforms use eventual consistency:

  • Like Counts: Update immediately on local node, replicate to other nodes asynchronously
  • Posts: Write to local node, propagate to other regions within seconds
  • Trade-off: Temporary inconsistencies acceptable for speed

Example: User likes a post:

  • Eventual Consistency: Update like count locally → Return success → Replicate to other data centers asynchronously
  • Result: User sees instant feedback, other users see update within seconds
  • Trade-off: Fast response, but temporary inconsistencies possible

Impact: Fast user experience. Handles millions of interactions. Acceptable inconsistencies for non-critical data.

The Challenge: Chat applications need to preserve message order. If User B replies to User A’s message, all users must see the original message before the reply.

The Solution: Chat applications use causal consistency:

  • Message Order: Preserves cause-and-effect relationships
  • Threads: Ensures replies appear after original messages
  • Trade-off: Stronger than eventual, but weaker than strong consistency

Example: User A posts message, User B replies:

  • Causal Consistency: Track dependencies → Ensure reply is seen only after original message
  • Result: All users see messages in logical order
  • Trade-off: Preserves causality without global coordination

Impact: Logical message order. No confusion. Better than eventual consistency for chat.

The Challenge: E-commerce platforms have different consistency needs for different data types.

The Solution: E-commerce platforms use hybrid approaches:

  • Product Catalog: Eventual consistency (fast updates, acceptable inconsistencies)
  • Inventory: Strong consistency (prevent overselling)
  • Reviews: Causal consistency (preserve reply order)

Example: Product page load:

  • Product Info: Eventual consistency (fast, may be slightly stale)
  • Inventory: Strong consistency (must be accurate)
  • Reviews: Causal consistency (preserve thread order)

Impact: Optimized for different data types. Right consistency model for each use case.



Strong consistency guarantees that all nodes see the same data immediately after a write completes.

Diagram

Key Characteristic: The write operation blocks until all replicas confirm. Only then does the client get a success response.

Diagram
AspectStrong Consistency
Data AccuracyAlways correct, no stale reads
Write LatencyHigher (waits for all replicas)
AvailabilityLower (if one node is down, writes may fail)
ComplexityHigher (need coordination, locks)
Use CasesFinancial systems, inventory, critical state

Eventual consistency allows temporary differences between nodes, but guarantees all nodes will eventually converge to the same state.

Diagram

Key Characteristic: The write returns immediately after updating the leader. Replication happens asynchronously in the background.

Diagram
AspectEventual Consistency
Data Accuracy⚠️ Temporary inconsistencies possible
Write LatencyLower (returns immediately)
AvailabilityHigher (can write even if some nodes down)
ComplexityLower (no coordination needed)
Use CasesSocial media, analytics, non-critical data

Causal consistency preserves cause-and-effect relationships. If event A causes event B, all nodes that see B must have already seen A.

Diagram

Causal consistency uses vector clocks or logical timestamps to track dependencies:

Diagram

Key Characteristic: Events are delivered in causal order, even if they arrive out of order.

Diagram
AspectCausal Consistency
Data AccuracyPreserves logical relationships
Write LatencyLower than strong (no global coordination)
AvailabilityHigher than strong consistency
Complexity⚠️ Medium (need dependency tracking)
Use CasesChat, comments, collaborative editing

Diagram
Use CaseConsistency ModelWhy
Bank balanceStrongCan’t have incorrect balances
Inventory countStrongCan’t oversell products
Social media likesEventualSpeed > exact count
View countsEventualApproximate is fine
Chat messagesCausalNeed logical order
Comment threadsCausalReplies must follow posts
User profilesEventualCan tolerate slight delays

How consistency models affect your class design:

When you need strong consistency, use synchronization primitives:

Eventual Consistency → Use Version Numbers

Section titled “Eventual Consistency → Use Version Numbers”

For eventual consistency, track versions to detect conflicts:

For causal consistency, maintain dependency graphs:

Causal Consistency with Dependencies
from typing import List, Set
class Event:
def __init__(self, data, dependencies: List[int]):
self.data = data
self.dependencies = set(dependencies) # Events this depends on
self.id = None # Assigned by system
class EventStore:
def __init__(self):
self.events = {} # id -> Event
self.seen = set() # Events this node has seen
def can_deliver(self, event: Event) -> bool:
# Can only deliver if all dependencies are seen
return event.dependencies.issubset(self.seen)
def deliver(self, event: Event):
if self.can_deliver(event):
self.seen.add(event.id)
# Process event...


Now that you understand consistency models, let’s explore the fundamental theorem that governs these trade-offs:

Next up: CAP Theorem Deep Dive — Learn why you can’t have everything: Consistency, Availability, and Partition tolerance.