Writes-Follow-Reads Consistency
What You'll Learn
You'll learn how writes-follow-reads consistency ensures that any write issued after a read reflects the state observed in that read, preserving causality in distributed sessions.
The Core Idea
Writes-follow-reads consistency (also called session causality) guarantees that if a client reads some data and then performs a write, that write will be applied to a system state that includes the data the client just read—or a later state. In other words, your write can't "go back in time" to a replica that hasn't yet seen the data you just read.
Why Does This Matter?
Imagine you're commenting on a social media post. You read the post (which says "I love pizza"), then write a comment: "Me too!" Without writes-follow-reads, your comment might be sent to a replica that hasn't received the post update yet. The system would try to attach your "Me too!" to a post that doesn't exist or has different content—breaking causality.
This consistency level ensures that writes respect the causal dependency established by prior reads in the same session. If you read version V3 of data, your subsequent write must be applied at V3 or later, never at V2.
How It Works
The system tracks which version or timestamp a client read. When that client issues a write, the coordinator ensures the write goes to a replica that has already processed that read version. This might involve:
- Routing writes to the same replica used for reads
- Attaching version metadata to write requests
- Using vector clocks or logical timestamps
Key Takeaway
Writes-follow-reads consistency preserves causality by ensuring writes are never applied to system states older than what the client has already observed, preventing "time travel" anomalies in distributed sessions.