Read-Your-Writes Consistency
What you'll learn: How to ensure a client always sees their own writes, even when reading from replicas.
The Core Problem
When using replication (especially asynchronous), a client might write data to the leader, then immediately read from a replica that hasn't received the update yet. This creates a jarring experience: "I just posted a comment — where did it go?"
Read-Your-Writes Consistency (also called "read-after-write consistency") guarantees that if a user writes something, any subsequent read by that same user will reflect their write, even if other users might not see it yet.
Why This Matters
Imagine posting a photo on social media. You hit "Post" and immediately refresh. If your photo doesn't appear, you'd assume something broke — even though it's just replication lag. Other users might tolerate slight delays, but you expect to see your own changes instantly.
This is different from broader consistency models. It's a user-centric guarantee focused on session continuity.
Common Implementation Strategies
-
Read-from-leader for own writes: After a write, that client reads from the leader (not replicas) for a period of time or until replication catches up.
-
Track write timestamps: The client remembers when they last wrote. Reads go to replicas only if the replica is caught up past that timestamp.
-
Session affinity (sticky sessions): Route all requests from a user to the same replica, ensuring it has seen all their writes.
-
Use version/logical clocks: Pass a version token with writes; only read from replicas that have processed at least that version.
Key Takeaway:
Read-Your-Writes Consistency ensures users always see their own changes immediately, providing a seamless experience even in eventually consistent, replicated systems.