Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

An order service writes an order and publishes an OrderCreated event; a customer-facing order history service builds its own read model from those events. A user places an order and immediately refreshes the history page but does not see it. Explain what eventual consistency means here and why this is expected behaviour.

Eventual consistency means that if no new writes arrive, every copy of the data, including the order history read model, will reach the same state after some delay. The history service builds its view asynchronously from OrderCreated events, so for a short window after the write it simply has not heard about the new order yet. That gap is expected: it is the price we pay for letting the read side scale and fail independently, and we handle it in the user experience rather than treating it as a bug.

Why this question is asked

As soon as we split one system into a write side and a separate read side connected by events, a user can do something and not see it straight away. Interviewers ask about it to see whether we understand that the delay is built into the design, how long it can be, and what we do so that users are not confused by it. In this answer, we will recap what eventual consistency means, follow one order from the write to the history page, look at where the lag comes from and how big it can get, explain why we accept it, and then go through the ways we keep the user from noticing it.

1A Quick Recap of Eventual Consistency

Consistency, in this setting, is about whether everyone who reads a piece of data sees the latest value. With strong consistency, once a write is acknowledged every later read sees it. With eventual consistency the promise is weaker: if writes stop, all copies of the data converge to the same state after some delay. Nothing says how long the delay is, only that it ends.

In our system there are two copies of the order. The order service owns the real one in its own database; it is called the write side or the source of truth. The order history service keeps a read model, a separate table shaped for the history page, which it fills by listening to events. An event such as OrderCreated is a message that says something has already happened. The read model is a derived copy, and a derived copy that is updated by messages is eventually consistent by nature.

2Following One Order From Write to History Page

Let us follow the order. The user clicks Place order. The order service inserts the row, commits its transaction and publishes OrderCreated to the broker, for example a Kafka topic. It returns 201 Created to the browser. At that moment the order exists, but only in the order service.

The history service has a consumer that polls the topic. On its next poll it receives the event, inserts a row into its own order_history table and commits its offset. Only now will the history page show the order. If the user refreshes between the 201 and that insert, the history service answers from a table that does not yet contain the order. Notice that nothing failed: each step did exactly what it should, just not at the same instant.

Step throughWhy the refresh misses the order
BrowserOrder serviceBrokerHistory service
POST /orders
insert order, commit
publish OrderCreated
201 Created
GET /history (refresh)
list without the new order
deliver OrderCreated
insert into order_history
GET /history (later)
list with the new order

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

The refresh arrived before the event did. A few hundred milliseconds later the same request shows the order.

3Where the Lag Comes From and How Big It Gets

The window between the write and the read model update is called replication lag or projection lag. It is the sum of several small delays: the time for the producer to send and the broker to replicate the message, the time until the consumer's next poll, the time to process the batch the event sits in, and the time to commit the read model write. On a healthy system with Kafka this is usually tens of milliseconds to a second or two.

But there is a catch: the lag has no upper bound when something goes wrong. If the history consumer crashes, the events wait in the topic until it restarts. If a poison message, a message the consumer cannot process, keeps failing and being retried, everything behind it on that partition waits too. During a traffic spike the consumer may fall minutes behind. So when we say eventually, we must be honest that eventually can mean seconds on a normal day and much longer during an incident.

Java
// A projection consumer that measures its own lag
@KafkaListener(topics = "orders", groupId = "order-history")
public void on(OrderCreated event) {
historyRepository.insert(HistoryRow.from(event));
Duration lag = Duration.between(event.occurredAt(), Instant.now());
lagTimer.record(lag); // e.g. 180 ms on a normal day, 4 min after a consumer restart
}

Recording the difference between when the event happened and when we applied it gives us a lag metric we can graph and alert on.

4Why This Is a Deliberate Trade, Not a Bug

We could make the history page strongly consistent by having it query the order service directly, or by writing both tables in one transaction. Both options couple the two services again. The history page would go down when the order service goes down, and a slow history query would slow down order placement. The separate read model exists precisely so that the read side can use its own schema, scale to many more reads than writes, and keep serving pages when the write side is busy or broken.

So eventual consistency is the cost of that independence. It is acceptable as long as two conditions hold: the lag is small enough for the business in normal operation, and we monitor it so we know when it is not. A history page that is one second behind is fine. One that is silently an hour behind is an incident, even though the mechanism is the same.

5Hiding the Lag From the User

The simplest fix is to not need a read straight after the write. The order service returns the created order in the body of its 201 response, and the frontend adds it to the list it is already showing. The user sees the order instantly, and by the time they navigate away and come back, the read model has caught up.

A second option is read-your-writes routing, a guarantee that a user always sees their own writes. For a short window after a user writes, their reads go to the source of truth instead of the read model, or the history service checks whether it has processed the event the client is waiting for. A third, often the most honest, is to show a pending state: the frontend keeps the order it just created with a label such as Processing until the history service returns it.

Java
// The write response carries what the client needs
@PostMapping("/orders")
ResponseEntity<OrderView> place(@RequestBody PlaceOrder cmd) {
Order order = orderService.place(cmd); // commit + publish
return ResponseEntity.created(URI.create("/orders/" + order.id()))
.body(OrderView.from(order)); // client shows it at once
}

Notice that none of these options removes eventual consistency from the system. They move the problem out of the user's way, which is what the product actually needed.

6Follow-up questions

How would you measure the lag between the write and the read model?

I would measure it in two ways. From the broker's side, consumer group lag tells how many messages the history consumer has not yet read, and Kafka exporters make it a metric per partition. From the data's side, I would put an occurredAt timestamp on every event and record the difference between that and the moment the projection commits, as a timer with percentiles. The second one is closer to what the user feels. I would alert on p99 of that time against a budget, for example 5 seconds, and on consumer lag that keeps growing.

Which screens in such a system must never read from an eventually consistent model?

Any screen where a stale value leads to a wrong decision with real cost. Typical examples are an account balance shown before a transfer, available stock at the moment of checkout, and the confirmation that a payment was taken. Those reads must go to the owning service and its database. A history list, a dashboard or search results can be eventual, because a short delay only means the user sees slightly old information.

7Conclusion

In this answer, we saw that the history service is a derived copy of the order data, filled asynchronously from events, so a refresh straight after placing the order can arrive before the event does. The lag is usually milliseconds to seconds but grows without limit during failures, which is why we measure it. We accept it on purpose because it lets the read side scale and fail independently, and we hide it from the user by returning the created order in the write response, routing a user's own reads to the source, or showing a pending state.

What to say in the interviewAbout 90 seconds aloud

Open with

What the user sees is eventual consistency working as designed. The order service commits the order and publishes OrderCreated, and the history service updates its own read model when it consumes that event.

Then, if they want more

Eventual consistency means that if no new writes come in, the read model converges to the same state as the order service, but there is a window where it lags behind. If the user refreshes inside that window, the history service simply has not processed the event yet.

That window is the sum of broker latency, the consumer's poll interval, processing time and retries.

Normally it is milliseconds to a couple of seconds, but it is unbounded when the consumer is down or stuck on a bad message, so I would always monitor it, for example with consumer lag and a timer from the event timestamp to the projection commit.

We accept this trade deliberately: it lets the read side have its own schema, scale separately and stay up when the order service is struggling. It is only a bug if the lag is unbounded or unmonitored. For the user, I would fix the experience rather than the architecture.

The simplest way is to return the created order in the 201 response so the frontend shows it immediately. Other options are read-your-writes routing for a short window after a write, or showing the order in a pending state until the history service returns it.

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 "An order service writes an order and publishes an OrderCreated event; a customer-facing...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/6229a024fb/