Video in progress

Strong Middle 🧩 Microservices

A user updates their profile and, after refreshing the page, sees the old data. How does this happen because of eventual consistency, and how do you solve it?

The write goes to one service, while the read comes from a read model or replica updated later through events, so there's a short window in between. The solutions: read from the write source for the user who just wrote, wait by version, or an optimistic update in the UI.

📖 Answer

This is a breach of the "read-your-writes" guarantee. If another user sees the profile 2 seconds stale, nobody notices. But if they see their own change in the old state, they keep clicking "it wasn't saved" and write to support.

Typical causes:

  • the read comes from a CQRS read model that hasn't yet processed the Kafka event;
  • the read goes to a DB replica with replication lag;
  • a gateway or CDN cache is returning the old response.

The solutions (often combined):

Read from the source after a write. If the user wrote in the last few seconds (a marker in the session), their own data is read from the primary or the writing service.

Wait with a version. The write response returns the new version, and the client sends minVersion=17 on read. If the read model is still at 16, the server waits a little or redirects to the source.

ProfileView v = viewRepo.find(userId);
if (v.version() < minVersion) {
    return profileServiceClient.get(userId);   // if it's stale, go to the source
}
return v;

At the UI level. Showing the saved value in local state without waiting for the response is the fastest solution for the user.

One more: after a write operation, evict the relevant cache key. The important thing is to acknowledge this problem at the design stage and discuss openly with the business "where how much delay is acceptable".