SA-301a · Module 2
Eventual Consistency Strategies
3 min read
Eventual consistency is the trade-off you accept when you adopt CQRS. The read model will lag the write model. The user who places an order and immediately refreshes the order list may not see it yet. This is not a bug — it is the architectural consequence of separating reads from writes. The question is not whether to accept eventual consistency. The question is how to make it invisible to the user.
- Optimistic UI Updates After the command succeeds, update the client UI immediately with the expected result — without waiting for the projection to catch up. The user sees the order in their list because the client inserted it locally. When the projection updates, the server-side data confirms what the client already shows. This eliminates perceived lag for 99% of interactions.
- Read-Your-Writes Consistency Route the user's subsequent reads through a path that guarantees they see their own writes. A version token returned by the command side can be passed to the query side: "return results only if your projection has processed at least this version." If the projection has not caught up, wait briefly or fall back to the command model.
- Compensating Actions When eventual consistency produces a user-visible inconsistency — the order that appeared briefly and then vanished because the command was rejected — the system must handle it gracefully. Compensating actions undo the optimistic update and explain why. "Your order could not be processed because the item is out of stock" is a graceful compensation. A silently disappearing order is not.