Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

A product page in your CQRS system is built from a read model updated by events. After a change, users see their own edits disappear for a few seconds and file bugs. How would you handle this across the UI and services?

The edits disappear because the product page reads a read model that is updated from events a little after the command commits, so a read right after a write still sees the old data. We fix the user's experience by returning the new state or version from the command so the UI shows it directly, by letting queries wait for a minimum version or read the write side for the user's own recent change, and we manage the system by measuring projection lag against an objective and agreeing with product owners which views may lag.

Why this question is asked

Eventual consistency is easy to accept on a whiteboard and very hard to accept as a user who just clicked Save and sees the old price. These bug reports are not wrong: from the user's side, the system lost their edit. Interviewers ask this scenario because it shows whether we can turn a theoretical property of CQRS into concrete design decisions in the UI, the API and operations. In this answer, we will see why the edit seems to vanish, then go through the fixes from the cheapest to the strongest, and finish with the metric and the agreement that keep the problem under control.

1Why the Edit Seems to Disappear

In a CQRS system the command and the query take different paths. The command updates the write model and commits, and an event such as ProductUpdated is published. A projection consumes that event and updates the read model the product page reads. Between the commit and the projection update there is a gap, usually tens of milliseconds, sometimes seconds when the consumer is busy, rebalancing or retrying.

The UI, meanwhile, does the natural thing: after the save succeeds it reloads the page. That reload reaches the read model inside the gap and gets the old version. A few seconds later the edit appears, which is why the users describe it as flickering or disappearing. This guarantee, that a user always sees their own writes, is called read-your-writes consistency, and our system does not provide it yet.

Step throughSaving a product and reading it back too early
BrowserCommand APIWrite DBProjectionRead model
PUT /products/7 (price 20)
update, version 5 -> 6, commit
200 OK
GET /products/7
price 18, version 5 (old)
ProductUpdated v6 (via outbox)
update to version 6

7 messages in order. Play them, or step through them one at a time.

The reload wins the race against the projection, so the user sees version 5.

2Fix 1: Return the New State From the Command

The cheapest fix is to stop asking the read model right after a write. The command already knows the new state, so it returns it, or at least the new version number, and the UI updates the page from that response instead of reloading.

Java
@PutMapping("/products/{id}")
public ProductView update(@PathVariable UUID id, @RequestBody UpdateProduct cmd) {
Product p = commands.update(id, cmd); // commits version 6
return ProductView.from(p); // { "price": 20, "version": 6 }
}
// UI: render the returned view; do not refetch immediately

This solves the most common complaint, the page right after Save, with no new infrastructure. Its limit is that other screens the user opens next, the product list or the search results, still read the read model and may still show version 5.

3Fix 2: Wait for a Minimum Version

For those other screens, the client can pass the version it knows about, and the query side waits briefly until the read model has caught up to at least that version. The read model must store the version of each row, which projections set from the event.

Java
@GetMapping("/products/{id}")
public ResponseEntity<ProductView> get(@PathVariable UUID id,
@RequestParam(defaultValue = "0") long minVersion) {
Instant deadline = clock.instant().plusMillis(500);
ProductView v = readModel.find(id);
while (v.version() < minVersion && clock.instant().isBefore(deadline)) {
sleepQuietly(25); // short poll; or listen for a projection signal
v = readModel.find(id);
}
if (v.version() < minVersion) {
return ResponseEntity.ok().header("X-Stale", "true").body(v); // let the UI say 'updating'
}
return ResponseEntity.ok(v); // version 6
}

Notice the deadline. We never wait forever, because a stuck projection would then block every page. If the version has not arrived in time, we return what we have and mark it as stale so the UI can show a small 'updating' note instead of silently showing old data. Polling is the simplest version; a projection can also publish a 'caught up to version N' signal that waiting requests listen for.

4Fix 3: Read the Write Side for the User's Own Recent Change

Another option is routing. For a short window after a user writes, say thirty seconds, their reads of that entity go to the write side, which is always current, and everyone else's reads go to the read model. The window can be tracked in the session or with a cookie holding the entity id and version.

This gives strong read-your-writes for the author while keeping the read model for the many other readers. It costs extra load on the write database and a second code path for the query, so it fits views of one entity, not search pages that only the read model can answer.

Choosing a fix by view
ApproachFixesCost
Return state from commandpage right after Savealmost none
Wait for minimum versionany view that has versionsslower reads in the gap, needs a timeout
Read write side for authorown entity viewswrite DB load, second code path
Show 'updating' in the UIeverything elsea design change, no backend work

5Measure Projection Lag and Agree Where It Is Acceptable

All these fixes assume the gap is short. So we measure it. Each projection records the time between an event's creation and the moment it was applied, as a Micrometer timer, and we also watch Kafka consumer lag for the projection's group. We set an objective, for example 99 percent of product updates visible in the read model within one second, and alert when it is missed. A growing lag is often the real bug behind a wave of 'lost edit' reports.

Finally, this is a product decision as much as a technical one. We sit down with the product owners and go through the views. A search result that is two seconds old is fine. A stock count shown at checkout, or a price the customer is about to pay, must not lag, so those read from the write side or from a source with a strict guarantee. Writing that agreement down stops the same debate from returning with every bug report.

6Follow-up questions

Why not make the projection synchronous, inside the command's transaction?

If the read model lives in the same database, we can update it in the same transaction and remove the lag entirely, which is a reasonable choice for one important view. But it couples the command to every read model, slows writes, and is impossible when the read model is a different store such as a search index. We usually reserve it for a single critical view.

How does the UI know which version to ask for?

The command response includes the new version, and the UI keeps it, for example in its state store or in the URL of the next request. For views that list many entities, the UI can remember the latest version of anything the user changed and ask the list endpoint to wait for it.

What happens with multiple tabs or devices?

Fix 1 only helps the tab that made the change. Version waiting and write-side routing based on the user's session work across tabs, and for devices we can store the user's last write version server side. Beyond that, a short 'updating' indicator is the honest answer.

7Conclusion

In this answer, we saw that users lose their edits because the read model lags behind the write side, and a read right after a write wins the race. We fixed the experience by returning the new state from the command, by letting queries wait briefly for a minimum version, and by sending the author's own reads to the write side for a short window. We kept the system healthy by measuring projection lag against an objective and by agreeing with product owners which views may lag and which must always be current.

What to say in the interviewAbout 80 seconds aloud

Open with

The read model is updated asynchronously from events, so right after a user saves, the page reload can reach the read model before the projection has applied the change, and they see the old version.

Then, if they want more

That is a missing read-your-writes guarantee, not lost data. My first fix is in the API and UI: the command returns the new state and version, and the UI renders that instead of refetching.

For other views I would let the query accept a minimum version and wait briefly, a few hundred milliseconds with a deadline, for the read model to catch up, and if it does not, return the data marked as stale so the UI can show that it is updating.

For views of the user's own entity, I can route their reads to the write side for a short window after the change.

Then I would treat lag as an operational metric: measure the time from event to applied in each projection, set an objective like 99 percent within one second, and alert on it, because rising lag often explains these bugs.

Finally I would agree with product owners which views can tolerate lag, like search, and which must not, like prices at checkout, and serve those from the write side.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A product page in your CQRS system is built from a read model updated by events. After a...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/8420c5a42c/