Course contentsShow
← System Design
Lesson 1360 of 1,91934. Data Replication StrategiesFree lesson

Monotonic Reads Across Replicas

Guaranteeing users never see data move backward in time when reading from different replicas.

Monotonic Reads Across Replicas

You'll learn: How to prevent users from seeing data "go backward in time" when reading from different replicas.


The Problem

Imagine you post a comment on social media, refresh the page, and your comment is there. You refresh again a minute later, and it's gone. Then you refresh once more, and it reappears. This bizarre experience happens when you read from different replicas with varying replication lag.

In asynchronous replication systems (which you just learned about), replicas may be seconds or even minutes behind the primary. If consecutive reads hit different replicas, you might see:

  1. First read: Hits Replica B (caught up through transaction #150)
  2. Second read: Hits Replica A (only caught up through transaction #148)

You've just time-traveled backward by two transactions.


The Guarantee

Monotonic Reads guarantees that if a user reads data at version N, all subsequent reads will return data at version N or later—never earlier. Time only moves forward for that user.


How to Achieve It

Session stickiness: Route all reads from a single user session to the same replica. If User Alice hits Replica B first, keep sending her to Replica B. This ensures she sees a consistent timeline.

Client-side tracking: The client remembers the last-seen transaction ID or timestamp. On each read, it tells the system "I've seen up to version 150," and the load balancer routes it to a replica at least that current.

Both approaches prevent the backward-time-travel problem while still allowing asynchronous replication's performance benefits.


Key Takeaway:
Monotonic Reads ensure users never see stale data after seeing fresher data—time flows forward consistently per user session, typically achieved through session stickiness or version tracking.