Monotonic Reads Guarantee
What you'll learn: How to prevent users from experiencing time going backward when reading from replicated databases.
The Problem: Time-Traveling Data
Imagine you check your bank balance on your phone and see 450 — not because money was spent, but because your second request hit a different read replica that's behind on replication. Now a third refresh shows $500 again. The data appears to jump backward and forward in time, creating a confusing and broken experience.
This happens because replication lag causes different replicas to have different states at any given moment. Without guarantees, your application might read from replica A (up-to-date), then replica B (lagging), showing you older data on the second read.
What Monotonic Reads Guarantees
Monotonic Reads is a consistency guarantee that ensures: once you've read a piece of data at a certain state, you'll never see an older version of that data in future reads.
Think of it like reading a book: you can skip ahead to Chapter 5, but you should never suddenly find yourself back at Chapter 3. Time moves forward, never backward.
How It's Implemented
The most common approach: route each user's reads to the same replica consistently (called "session affinity" or "sticky sessions"). This can be done by:
- Hashing the user ID to always select the same replica
- Using load balancer session persistence
- Client-side replica selection logic
This doesn't eliminate replication lag, but it ensures your view of the data only moves forward.
Key Takeaway: Monotonic Reads guarantee prevents users from seeing data move backward in time by ensuring each user consistently reads from replicas that are at least as up-to-date as their previous reads, typically via session affinity.