You post a photo on a social media app, then immediately refresh the page and the photo is missing. What session guarantee is being violated here, and what would need to change for the app to satisfy it?
answer
- own write visible to self
- sticky routing or version token
- per-client, not global
- DynamoDB strongly-consistent read
- Cosmos DB session token
basics
~10 sThis breaks 'read-your-writes' — after you write something, you should always be able to read it back yourself, even if other users still see stale data for a while.
solid answer
~40 sRead-your-writes (RYW) is a client-centric session guarantee: once a specific client has written a value, all of that client's subsequent reads must reflect that write or something newer — never something older. In an eventually consistent system, a write may land on one replica and a read may be routed to another replica that hasn't received it yet, causing exactly this 'my own write vanished' bug. Fixing it means tying the read to the write: route the client's reads to the replica it wrote to (sticky routing), have the client send a version/timestamp token from its write and require the read replica to be at least that fresh, or read from a quorum that overlaps the write quorum.
go deeper
Should recognize the symptom (own write disappearing) and name it as read-your-writes; doesn't need implementation detail.
Should propose at least one concrete mechanism (sticky routing or version token) and explain why plain eventual consistency doesn't provide RYW for free.
Should compare 2-3 implementation strategies with their latency/availability trade-offs and identify failure modes like failover breaking affinity.
Should reason about RYW as a per-endpoint policy decision — where the latency/cost tax is worth it versus where UI-level workarounds (optimistic local state) are cheaper and sufficient.
## The promise Read-your-writes (RYW) is one of four 'session guarantees' first formalized by Terry et al. in the Bayou project (1994) to make eventually consistent systems tolerable for a single user, even though the system as a whole remains relaxed. The core idea: from the point of view of one client's own session, time should never appear to run backwards with respect to that client's own actions. If a client just wrote a value, every read it issues afterward must return that value or something even newer, never an older one. ## Why a read can miss its own write Mechanism, step by step: a write is accepted and lands durably on some replica, say A. If the client's next read is load-balanced to a different replica B that hasn't yet received the replicated write, B answers with stale data and the client's own change appears to have vanished. Fixing this requires tying the read to the write in one of a few ways. - **Sticky sessions/session affinity** pin a client's requests to the same replica or partition it wrote to, so subsequent reads naturally see the write. - **Version-stamped reads** have the client carry forward a token (a vector clock entry, a log sequence number, or a simple version integer) returned by the write, and pass it on every subsequent read; the serving replica must either be at or beyond that version, wait until it catches up, or proxy the read to a replica that is. - **Quorum-based systems** get RYW as a byproduct of overlapping read/write quorums (`W + R > N`), since any read set is mathematically guaranteed to intersect the write set. ## What makes this the bug users notice Why it exists: not every client needs strong, system-wide consistency, but every single client cares deeply about seeing the effect of its own actions — it is the single most visible correctness bug an eventually consistent system can produce, because it directly contradicts the user's own recent, remembered action: - a posted comment disappearing, - a saved profile edit reverting, - a removed cart item reappearing. ## What each mechanism costs Trade-offs: - **Sticky sessions** reduce load-balancing flexibility and complicate failover — if the pinned replica or server dies, the client either briefly loses the guarantee or must be handed a durable token it can carry to whatever replica serves it next. - **Version tokens** add protocol complexity (issuing, storing, expiring, and validating them) and can add tail latency whenever the serving replica must catch up before answering. - **Quorum overlap** gives RYW essentially 'for free' but taxes every single read and write with the coordination cost of contacting multiple replicas, even for data nobody but the writer will ever check freshness on. ## How it breaks in production Failure modes in production: RYW quietly breaks 1. when a client's requests get rebalanced across backends after a deploy, connection reset, or autoscaling event that drops sticky affinity; 2. when a CDN or read-through cache sits in front of the version-aware backend and serves stale bytes with no concept of the token at all; 3. or in multi-device scenarios where a naive implementation ties RYW to one TCP connection instead of a durable per-user identity, so a user's phone doesn't see an edit made moments earlier on their laptop (that specific cross-device case is really the job of writes-follow-reads/causal consistency, not RYW as classically defined, but it is frequently what users mean when they report 'my change disappeared'). ## Where you see it in practice Real-world example: - **Amazon DynamoDB** exposes 'eventually consistent reads' (cheap, fast, may violate RYW) and 'strongly consistent reads' (slower, roughly double the read-capacity cost, guarantees RYW and more) as an explicit per-request choice, and engineers are expected to pick strongly consistent reads specifically for the read immediately following a write when the UI must reflect it. - **Azure Cosmos DB's 'Session' consistency level** does the version-token approach directly: every request carries a session token the server must be at or beyond before answering, implementing RYW (and the other three session guarantees) for that one client without paying for full strong consistency platform-wide.
- How would sticky sessions alone fail to guarantee read-your-writes during a server failover?If the replica or server instance handling a client's session crashes or is redeployed, the load balancer must route subsequent requests elsewhere, breaking the affinity that made RYW work; unless the new server has already received the write, or the client carries a version token it can wait on, the client can briefly see a regression. This is why sticky sessions alone are a weaker, availability-fragile way to implement RYW compared to version-token approaches.
- Why doesn't reading from a quorum fully solve read-your-writes for a user switching devices?A quorum read guarantees the client sees the most recent write known to that quorum, but if the user's other device wrote through a different, not-yet-synced replica set, or the write itself hasn't reached quorum durability yet, a fresh device can still miss it. RYW is defined per logical session, so guaranteeing it across a user's devices additionally requires linking sessions via a shared user-level token, not just per-connection quorum reads.
- What's the cost of always using DynamoDB-style strongly consistent reads to guarantee RYW everywhere?Strongly consistent reads in DynamoDB cost roughly double the read capacity, carry higher latency, and can be unavailable during certain regional failover windows, whereas eventually consistent reads are cheaper and always available. Using them everywhere sacrifices the availability and cost benefits that eventual consistency was adopted for in the first place.
It's like updating your own edit on a shared document and then reopening it yourself — you should always see your own edit immediately, even if a friend viewing a cached mirror of the same document still sees the old version for a few seconds.
saying these in an interview costs you the question
- Says eventual consistency means you can never see your own writes
- Thinks RYW is automatically guaranteed by any distributed database with no extra mechanism
- Conflates read-your-writes with strong/linearizable consistency for all clients
- Doesn't mention any implementation mechanism (routing, token, quorum)
- Assumes sticky sessions alone are sufficient with no failover caveat