Articles

Read-Your-Writes Consistency Explained

Read-your-writes consistency guarantees a client sees its own writes immediately, even when other clients might not yet. How it's implemented.

The Lycoris Team The Lycoris Team · · 4 min read
Abstract database illustration

Read-your-writes consistency is a guarantee that once a client writes data, that same client will see the write reflected in every subsequent read it performs — even if other clients elsewhere in the system might still be reading stale data for a little while longer. It’s one of several “session guarantees” that sit between strict consistency and full eventual consistency, and it’s often the specific guarantee that actually matters for a given feature, even when a system is described more loosely as “eventually consistent.”

Why this needs a name at all

In a system with a single database and no caching, read-your-writes is automatic — you write, then you read, and the read hits the same data. The guarantee becomes interesting, and non-trivial to provide, the moment a system introduces replication or caching to scale reads. If writes go to a primary node and reads are load-balanced across replicas, a client can write successfully, then have its very next read routed to a replica that hasn’t yet received that write via replication. From the client’s point of view, its own change appears to have vanished.

This is a common source of confusing bug reports: “I updated my profile and it reverted a second later” is very often a read-your-writes violation, not data loss — the write succeeded, but a subsequent read happened to land on a lagging replica.

Where it sits among consistency models

Consistency models exist on a spectrum, trading strictness for performance and availability:

ModelGuaranteeCost
Strong (linearizable)Every read sees the latest write, from any client, immediatelyHighest — often requires coordination on every read
Read-your-writesA client sees its own writes immediately; other clients may lagModerate — requires tracking per-client write state
Monotonic readsOnce a client sees a value, it won’t later see an older oneModerate — requires tracking a client’s read progress
Eventual consistencyAll replicas converge eventually, with no timing guaranteeLowest — no coordination required

Read-your-writes is a session guarantee: it’s scoped to a single client’s sequence of operations, not to the system as a whole. Two different users can have wildly different views of the data at the same instant and the guarantee still holds, as long as each user’s own writes are visible to their own subsequent reads. This is part of why the CAP theorem’s consistency-versus-availability trade-off isn’t all-or-nothing in practice — many real systems pick a middle ground like this one rather than choosing pure strong or pure eventual consistency, a pattern explored further in the PACELC theorem.

How systems actually implement it

Route the client’s own reads to the primary. The simplest approach: after a write, route that client’s subsequent reads (or reads within some time window) to the node that accepted the write, rather than to a replica. This is easy to reason about but can undercut the scaling benefit of having replicas in the first place if applied too broadly — usually it’s scoped to just-written records or a short session window rather than every read forever.

Track a version or timestamp with the write, and require reads to catch up to it. The client remembers a version number or timestamp returned by its write. On the next read, it passes that version along, and the system routes the request to (or waits for) a replica that has caught up to at least that version. This preserves more of the scaling benefit of replicas, at the cost of some added bookkeeping and occasional added latency while a lagging replica catches up.

Read from a synchronous replica for that data. If a subset of writes are replicated synchronously (the write isn’t acknowledged until at least one replica confirms it), reads can safely be routed to that replica, since it’s guaranteed to already have the data. This trades write latency for read flexibility.

Cache invalidation on write. In systems where reads are served from a cache rather than replicas, the write path can proactively invalidate or update the relevant cache entries for that client, so a subsequent read doesn’t serve a stale cached value. This is a narrower, cache-specific instance of the same underlying problem.

Read-your-writes is often bundled with, but is not the same as, monotonic reads (a guarantee that a client’s reads never go backward in time, even without an intervening write) and monotonic writes (a guarantee that a client’s writes are applied in the order it issued them). Systems that advertise “session consistency” typically bundle all three. It’s also worth distinguishing this from the ACID vs BASE framing: read-your-writes is a consistency guarantee that a distributed, eventually-consistent (BASE-style) system can still choose to provide on top of its weaker baseline, rather than a property exclusive to ACID transactional databases. See database isolation levels for the closely related but distinct question of what a single transaction is allowed to see of concurrent, uncommitted changes within one database instance.

The takeaway

Read-your-writes consistency guarantees that a client always sees the effects of its own writes on its next read, even in a replicated or cached system where other clients might briefly see stale data. It’s typically implemented by routing a client’s post-write reads to the primary, tracking a version the client has already seen, reading from a synchronous replica, or invalidating caches on write. Understanding which consistency guarantees a system actually provides — rather than assuming “eventually consistent” means no guarantees at all — is often the difference between a confusing intermittent bug and a system whose behavior you can reason about.

Chisato Chisato · · 4 min read

Byzantine Fault Tolerance Explained

Byzantine fault tolerance lets a distributed system keep working correctly even when some nodes fail arbitrarily or actively lie, not just crash cleanly.

#Distributed Systems #Computer Science #Databases
Chisato Chisato · · 5 min read

Raft vs Paxos: Consensus Algorithms Compared

Raft and Paxos both let a distributed cluster agree on a value despite failures — Raft trades some flexibility for a design built to be understood.

#Distributed Systems #Computer Science #Databases
The Lycoris Team The Lycoris Team · · 5 min read

Two-Phase Commit vs. Saga Pattern Explained

Two-phase commit locks resources until every node agrees to a transaction; the saga pattern trades that guarantee for availability using compensating steps.

#Databases #Distributed Systems #Computer Science