Intermediate LevelSystem Design & Architecture
How do you handle Eventual Consistency Lag in CQRS Read Models?
β Interview Prompt: Explain CQRS eventual consistency lag, UI optimist updates, polling, WebSocket read model push, and read-your-writes guarantees.
In a CQRS architecture, read models are updated asynchronously from the write event stream, creating a brief window of eventual consistency lag (~10-100ms):
UX Handling Strategies:
1
Optimistic UI Updates: Client UI instantly renders the user's mutation locally before server event confirmation.
2
Read-Your-Writes Fallback: Route queries to the primary write model for $N$ seconds after a user mutation.
3
WebSocket Push: Push updated read model projections to the client UI over WebSockets as soon as projection completes.
Code Implementation Example
typescript
// Optimistic UI update handling
function handleFormSubmit(newComment: string) {
// 1. Instantly append comment to local UI list (Optimistic!)
appendCommentToUi(newComment);
// 2. Submit mutation to server asynchronously
api.post('/comments', { body: newComment }).catch(() => rollbackUi());
}π‘Executing optimistic UI updates to mask eventual consistency lag.
π― Interview Key Takeaway
Mask CQRS eventual consistency lag using optimistic UI updates and sticky read-your-writes routing.
#System Design#CQRS#Eventual Consistency#UX#Intermediate
Back to all System Design & Architecture Questionsβ