QA
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→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?