A distributed key-value store is eventually consistent. Explain what each of these client-side session guarantees promises — monotonic reads, read-your-writes, monotonic writes, and writes-follow-reads — and give one concrete bug that appears when each is absent.
answer
- Bayou paper, four session guarantees
- monotonic reads = no time regression
- monotonic writes = write ordering preserved
- writes-follow-reads = causal dependency
- Cosmos DB session token = all four
basics
~20 sThey're four separate promises to one user's session so nothing feels broken: reads won't go backward in time, you'll always see your own writes, your writes won't get reordered, and anything you read before writing will be visible to anyone who later sees that write.
solid answer
~50 sThese are the four classic session guarantees from Terry's Bayou paper. Monotonic reads: successive reads by a client never go back in time — no seeing v2 then v1. Read-your-writes: a client's reads always reflect its own prior writes. Monotonic writes: a client's writes are applied in the order it issued them, never reordered. Writes-follow-reads: if a client reads value X and then writes Y, any replica that later exposes Y must also expose X or something newer — the write is causally ordered after what was read. Each is implemented by carrying session state (a version vector, LSN, or replica-affinity token) between a client's operations so the server can route to a sufficiently fresh replica or block until caught up. Absent guarantees produce classic bugs: flip-flopping UI values, vanishing writes, out-of-order edits, and 'orphaned' content that references something the reader hasn't actually seen yet.
go deeper
Should be able to restate each guarantee's promise in plain language, even without implementation detail.
Should connect each guarantee to a concrete bug it prevents and name at least one mechanism, such as tokens or sequence numbers, for at least two of them.
Should explain the propagation and bookkeeping mechanism for all four, the cost each imposes, and correctly state that they are per-session, not cross-client.
Should discuss real production systems, such as Cosmos DB session consistency, and when it's worth offering these guarantees as a selectable consistency level versus baking in stronger guarantees everywhere.
## Where the four come from The four session guarantees were introduced in the Bayou project at PARC in the mid-1990s to give individual clients a locally coherent experience on top of a system that, in aggregate, only promises eventual consistency. They don't strengthen the system's global consistency; they strengthen what one client session — one logical thread of a user's interactions — is allowed to observe. ## The four, one by one - **Monotonic reads** means that once a client has observed a value at version `V`, it will never subsequently observe a value older than `V`, even talking to a different replica. Mechanically this requires the client to carry forward a high-water mark (a version vector, Lamport timestamp, or per-partition sequence number) from each read to the next; the server serving that next read must either route to a replica at or beyond that mark, or block/proxy until it catches up. Without this, a classic bug is a user refreshing a feed and, due to round-robin balancing hitting a lagging replica, seeing a comment count regress from 42 to 40 before jumping back to 42 — visibly incoherent. - **Read-your-writes** ensures a client sees its own writes reflected in its own subsequent reads, implemented via sticky routing, version tokens carried from write acknowledgment to read request, or quorum overlap. Absent, users see their own posts or edits vanish immediately after submitting them. - **Monotonic writes** ensures a single client's writes are applied to storage in the order the client issued them — write `W1` then `W2` must never be applied as `W2` then `W1` on any replica. This matters even within one client because network retries, out-of-order packet delivery, or two concurrent connections from the same client (two browser tabs) can otherwise reorder writes at the storage layer. It is typically implemented by having each client attach a strictly increasing per-client sequence number to its writes, with replicas applying writes only in sequence order, buffering or rejecting arrivals that are out of order. Absent, a user editing a document title twice in quick succession ('Draft' then 'Final') could end up with a replica showing 'Draft' because the second write raced ahead and applied before the first write's retry landed. - **Writes-follow-reads**, also called session causality, is the subtlest: if a client reads value `X` and then performs a write `Y`, that write is causally dependent on `X`, and any replica exposing `Y` must also expose `X` (or something at least as new). Concretely: a user reads a forum post, then writes a reply referencing it; another user must never see the reply without being able to see the post it replies to. It is implemented by attaching the version or vector-clock of everything the client has read to its next write, so the write carries an explicit causal dependency that replicas must respect before exposing it. Absent, you get orphan writes — a reply visible with its parent comment missing, which is confusing and occasionally security-relevant, such as a permission-revoking write becoming visible before the resource it protects. ## What all four cost Trade-offs across all four: each requires carrying and checking session state on every operation, costing client-side bookkeeping, server-side freshness checks, and tail latency whenever the target replica must catch up before answering. None of the four guarantees anything between two DIFFERENT client sessions talking to each other in real time — that is what stronger, system-wide models like causal consistency or linearizability address, at much higher coordination cost. ## How they break in production Failure modes in production: these guarantees silently break 1. when session tokens aren't propagated across service boundaries (a mobile app's token doesn't survive a restart, a microservice fan-out drops a header), 2. when load balancers route around sticky affinity during autoscaling, 3. or when a cache layer such as a CDN or browser cache sits in front of a version-aware backend and serves stale content with no token check at all. ## Where you see it in practice Real-world usage: Azure Cosmos DB's 'Session' consistency level implements exactly these four guarantees for a single client by passing a session token with every request, enforced server-side per-partition; it is Cosmos DB's default and most-used level precisely because it delivers a near-strong-consistency user experience at a fraction of the cost of full strong consistency.
- Which of the four session guarantees, if any, also protects consistency between two different users' sessions?None of them do on their own — all four are defined per single client session and say nothing about what a different client sees or when. Cross-client causal visibility, such as guaranteeing every user sees a reply only after its parent post, requires a system-wide model like causal consistency, which is strictly stronger and more expensive than any single session guarantee.
- How would you implement monotonic writes if a client can have two open connections, like two browser tabs, issuing writes concurrently?You need a single shared per-client sequence counter that both connections increment through, typically coordinated via a shared session token or server-assigned client ID rather than a local in-memory counter per connection. Some systems instead accept writes with client-supplied logical timestamps and let the storage layer apply conflict resolution such as last-writer-wins, converting the two-tabs problem into a conflict-resolution problem instead of a strict-ordering one.
- Why is writes-follow-reads considered the hardest of the four to implement cheaply?It requires the server to track and validate a causal dependency attached to every subsequent write, and to potentially block or delay the write's visibility until every replica exposing it has already caught up on that dependency. This is strictly more expensive than tracking a single high-water mark, because dependencies can span multiple keys or partitions, not just one client's own linear read/write history.
Think of four separate promises a restaurant makes about you personally, not about every customer: they won't seat you at a table that looks freshly dirty after you've already seen it cleared (monotonic reads), they'll remember the dish you just ordered when you ask for the check (read-your-writes), they'll cook your courses in the order you ordered them (monotonic writes), and if you complain about a dish before ordering dessert, the kitchen won't tell another table about your dessert order before that table has also heard about the dish you complained about (writes-follow-reads).
saying these in an interview costs you the question
- Treats the four guarantees as interchangeable or as one single concept
- Believes any one of them implies system-wide or global consistency
- Can't name a concrete bug scenario for at least two of the four
- Thinks these guarantees eliminate the need for conflict resolution
- Doesn't mention any propagation mechanism such as tokens, vectors, or sequence numbers