What you'll learn: By the end of this lesson you will be able to say what eventual consistency does and does not promise a user, name the screens where its inconsistency window becomes visible, apply four design moves (show the user's own write, report pending work with an honest status, label or avoid stale numbers, detect conflicting edits), and write copy and status codes that stay true while the system catches up.
Think of the arrivals board at a station. A train has pulled in, but the board still says "5 minutes". Nobody is surprised: the board is a copy of the timetable and copies lag. Users forgive a screen that is a little behind. They do not forgive one that contradicts what they just did.
The example is ShopStream, the grocery marketplace: a shopper places an order, and the orders list they open next is read from a replica that has not yet applied the write. The models are taught in Consistency Models and the replica mechanics in Replication Lag and Read-Your-Writes. This lesson takes the user's side.
The core idea
Eventual consistency is a promise about where the system ends up, not about what any single screen shows on the way there. Werner Vogels defines it as: if no new updates are made to the object, eventually all accesses will return the last updated value. The period before that is the inconsistency window, which he says depends on factors such as communication delays, the load on the system and the number of replicas.
The user lives inside that window. Nothing in the promise forbids an empty list right after a successful write, or a status that appears to go backwards. Vogels adds that the developer needs to be aware of the guarantees a storage system gives and build around them. It is often a per-read choice: at the time of writing, Amazon DynamoDB makes eventually consistent reads the default and offers a ConsistentRead parameter for strongly consistent ones on tables and local secondary indexes, while global secondary index reads are always eventually consistent.
Where the window shows
| Screen | What the user may see | Harm |
|---|---|---|
| Orders list | An empty list after placing an order | Orders again |
| Order status | An older status than a minute ago | Distrust |
| Product page | Stock that was true a moment ago | A sold-out item |
| Edit form | Someone else's edit overwritten | A lost update |
Figure 1. Where the lag sits
How to read this: the write lands on the accent box and travels to the warning box on its own schedule. A read that goes to the warning box in between is the empty list.
Four design moves
1. Show the user their own write
The session guarantee to restore is read-your-writes. Terry et al. define it as: if a read follows a write in a session and is performed at a server at time t, the write is included in that server's data at t. Vogels' version: after a process has updated an item, it always accesses the updated value and never sees an older one. The back end can route such reads (the replication lesson compares four ways). A cheaper move: the write's response already contains the new order, so the client keeps it and merges it with later list reads by id.
Illustration 1: the minimal example
A replica that applies each write 2 ticks after the primary (illustrative), and two ways to render the orders list after one order. Run in Node:
const LAG = 2; // illustrative: the replica applies a write 2 ticks after the primary
function makeStore() {
const s = { tick: 0, primary: [], replica: [], inflight: [] };
s.write = (item) => { s.primary.push(item); s.inflight.push({ due: s.tick + LAG, item }); };
s.advance = () => {
s.tick++;
for (const w of s.inflight.filter((x) => x.due <= s.tick)) s.replica.push(w.item);
s.inflight = s.inflight.filter((x) => x.due > s.tick);
};
s.readReplica = () => [...s.replica];
return s;
}
const store = makeStore();
const order = { id: "o-1001", total: 18.4 };
store.write(order); // the checkout call returns the created order to the client
const kept = [{ ...order, pending: true }]; // the client keeps it, marked pending
const naive = () => {
const rows = store.readReplica();
return rows.length ? rows.map((r) => r.id).join(",") : "You have no orders yet";
};
const merged = () => {
const seen = new Map(store.readReplica().map((r) => [r.id, { ...r, pending: false }]));
for (const k of kept) if (!seen.has(k.id)) seen.set(k.id, k);
return [...seen.values()].map((r) => r.id + (r.pending ? " (processing)" : "")).join(",");
};
for (let t = 0; t <= 3; t++) {
console.log("t=" + t, "| list from replica only:", naive().padEnd(24), "| list merged with own write:", merged());
store.advance();
}
Output, from running it in Node 26.13.1:
t=0 | list from replica only: You have no orders yet | list merged with own write: o-1001 (processing)
t=1 | list from replica only: You have no orders yet | list merged with own write: o-1001 (processing)
t=2 | list from replica only: o-1001 | list merged with own write: o-1001
t=3 | list from replica only: o-1001 | list merged with own write: o-1001
The naive list tells a shopper with an order that they have none. The merged list shows it at once, marked as processing, with no duplicate row once the replica catches up because both sources use the same id. The model shows the logic only; real lag is variable.
2. Report pending work honestly
Some work is not done when the request returns. HTTP has a status for that. MDN describes 202 Accepted as meaning the request was accepted for processing, but processing has not been completed or may not have started, and notes that it is non-committal: the actual processing is not guaranteed, and a task may fail or be disallowed when the server tries it. The Azure asynchronous request-reply pattern gives the usual shape: the API answers 202 with a Location header pointing to a status endpoint, the client polls it, the endpoint returns 200 with the current state while work is pending, and a 303 redirect to the result when it finishes. It also suggests a Retry-After header and an idempotency key so a retried POST does not queue the work twice.
Figure 2. An order that is accepted before it is done
How to read this: the screen is honest at every step because each state it shows is a state the system has actually reached.
The states must be a closed set the UI can render, including a failure.
Figure 3. Order states the screen can show
How to read this: "Rejected" exists on purpose. If the design only has a path to success, an async failure has nowhere to show up.
3. Label stale data, or do not show it as exact
If a number cannot be exact, do not present it as exact: "Low stock" stays true longer than "2 left". Monotonic reads, in Terry et al., mean a later read in a session never sees an older state than an earlier one; without them a refresh can show Packed after Out for delivery by landing on a lagging replica. The fix is a version in the response that the client sends back as a minimum, or sticky routing (see the replication lesson).
4. Detect conflicting edits
Two sessions that edit one record both read before either writes. The HTTP answer is a conditional request: the client sends the ETag it read in an If-Match header, and if the stored version differs the server returns 412 Precondition Failed. MDN says If-Match can be used on PUT to prevent the lost update problem, overwriting a change made since the resource was fetched. The UI then says "this changed, review and retry".
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Return the written state, merge on the client | No replica routing | Client merge logic |
| Route reads to the primary after a write | Correct own-write view | Primary load |
| 202 with a status resource | Honest, fast responses | A status endpoint and polling |
| Strongly consistent read | Latest data | Cost, and not offered everywhere |
If-Match on edits |
No lost updates | Clients handle 412 |
Build it
This lesson has no lab. The Node script above is the only code that ran; it models a fixed-lag replica and shows no database or HTTP behaviour. The 202, ETag and If-Match behaviours come from the linked sources and were not exercised in code.
The other side of this topic
On the front end the same facts appear as optimistic updates: the interface shows an action as done before the server confirms it and rolls back if the server disagrees. See Optimistic Updates and Rollback and Offline-First Sync and Conflict Resolution. The back end's part is to return states and versions the interface can act on.
In practice: the orders list that said "none"
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
After placing an order, a shopper taps "My orders" and sees "You have no orders yet". Some (illustratively 1 in 20) order again, and support refunds the duplicates.
Starting architecture
Figure 4. Lists read from a replica
How to read this: the warning boxes are the cause. The write returns nothing the client can keep, and every list goes to the replica.
Options considered
Reading the primary for a short time after a write fixes the list at the cost of primary load. Returning the order in the response and merging on the client is cheaper but needs client code. A visible "processing" status is honest but needs a status model.
The decision
Return the created order with status pending (202 with a Location), merge it into the list by id and show "Processing".
Rollout and verification
- Test that an empty replica plus a kept order renders one row.
- Delay the replica in a test environment and check the list and the copy.
- Watch repeat orders per shopper before and after.
The 2 a.m. failure
A payment check starts failing and orders sit in Pending for hours. First three checks: (1) how many orders are older than expected; (2) whether the worker is consuming; (3) whether the UI shows only "Processing". Mitigation: a message after the expected time. Follow-up: alert on the age of the oldest pending order.
Architect's notes
- Name the inconsistency window for each screen and write copy that is true inside it.
- Return the state you wrote. It is the cheapest read-your-writes.
- Give async work a status resource and a failure state.
Common mistakes
- An empty-state message for a list that has not caught up.
- A success screen for work that is only accepted.
- No failure state, so a late rejection has nowhere to show.
Key takeaways
- Eventual consistency promises where the system ends up; the user sees the path.
- Restore read-your-writes by returning and merging the user's own write.
- Report accepted work as pending, with a status resource and a failure state.
- Label or soften numbers that cannot be exact.
- Use
ETagandIf-Matchso a conflicting edit fails visibly.
Practice exercises
Exercise 1: Starter (20 min). Change LAG in the script to 5 and predict the output before running it.
Exercise 2: Intermediate (2 hours). Add a rejected order to the model and write the copy the shopper sees.
Exercise 3: Advanced (half day). Design a version token that gives monotonic reads for order status, and say where the client sends it.
Related reading
In this course:
- Consistency Models: Linearizable to Eventual: the ladder of models and the session guarantees.
- Replication Lag and Read-Your-Writes: the routing policies behind move 1.
- CAP Theorem and PACELC: why the choice exists.
- Optimistic Updates and Rollback: the front-end view.
Official documentation
- Vogels: Eventually Consistent: definition, window and session guarantees.
- Terry et al.: Session Guarantees for Weakly Consistent Replicated Data: read-your-writes and monotonic reads.
- Amazon DynamoDB: Read consistency: eventual and strong reads.
- Azure Architecture Center: Asynchronous Request-Reply pattern: 202, status endpoint, 303.
- MDN: 202 Accepted and If-Match: accepted work and conditional writes.