CQRS in System Design Interviews: When to Use It and What to Say
CQRS (Command Query Responsibility Segregation) is a pattern that separates the part of a system that handles state-changing commands from the part that serves read-only queries. By giving each side its own data model and often its own storage, you can tune them independently and avoid the write-read contention that hurts scalability.
The Problem CQRS Solves
Most applications start with a single data model that handles both writes and reads. That works for low traffic, but it creates three bottlenecks when the system grows:
- Write-read contention – every write locks the same tables that many reads need, causing latency spikes.
- Different performance goals – writes need durability and validation, while reads need low latency and flexible indexing.
- Scaling mismatch – a service may need to scale reads to thousands of requests per second while writes stay at a few hundred.
A concrete example is an online store’s product catalog. Customers browse products (reads) many times per second, but inventory updates (writes) happen far less often. If you keep a single relational table for both, the read path suffers whenever a write transaction locks rows or the table.
How CQRS Works – Step by Step
Below is a minimal worked example for a shopping cart service.
- Command side – A client sends a
AddItemcommand. The API validates the request, writes an eventItemAddedto a durable log (e.g., Kafka), and updates a write-optimized store (often a relational DB). The command returns immediately after the write succeeds. - Event propagation – The
ItemAddedevent is published to a message broker. Consumers subscribe to this topic. - Read side – A separate process consumes the event and updates a read-optimized view, such as a denormalized document in DynamoDB or Elasticsearch. This view is built for the query patterns you need (e.g., "get current cart for user").
- Query – When the UI asks for the cart, the query service reads directly from the denormalized view, bypassing the write store entirely.
- Consistency – Because the read side updates after the event is persisted, there is a short window of eventual consistency. Most e-commerce experiences tolerate a few hundred milliseconds of lag.
The key is that the command path never touches the read store, and the read path never triggers business logic that mutates state. Each side can use the storage technology that best fits its access pattern.
Classic Interview Questions Where CQRS Appears
| Interview Question | Where CQRS Fits | Why It Helps |
|---|---|---|
| High-traffic e-commerce catalog | Separate product-detail write model from a search-optimized read index | Allows scaling of product search to many requests per second while writes stay low |
| Social media news feed | Commands write new posts to an event log; read side builds per-user timelines in a NoSQL store | Supports fan-out to millions of followers without slowing down post creation |
| Ticket booking system | Commands reserve seats and emit events; read side maintains a seat-availability view | Guarantees durability of reservations while serving fast availability checks |
In each case, the interview often asks you to handle a read-heavy workload with strict latency requirements. Mentioning CQRS signals that you recognize the mismatch between write and read scaling.
Trade-offs and the Alternative Interviewer May Probe
| Aspect | CQRS | Single-model (no CQRS) |
|---|---|---|
| Complexity | Adds extra components: event bus, separate stores, sync logic | Simpler architecture, fewer moving parts |
| Consistency | Eventual consistency for reads; you must handle stale data | Strong consistency; reads see the latest write immediately |
| Operational overhead | Need to monitor two data pipelines, handle replay, and version events | One pipeline to monitor, easier backup/restore |
| Scalability | Reads and writes can be scaled independently, using different technologies | Scaling limited by the bottleneck of the single store |
Interviewers often follow up with: "What if you don’t want eventual consistency?" The usual answer is to use a single-model approach or to add a read-through cache with write-through invalidation, trading some read latency for stronger consistency.
30-Second Pitch
"CQRS splits the system into a command side that validates and persists state-changing operations, and a query side that serves reads from a denormalized view. This lets you scale reads and writes independently, use the best storage for each, and handle read-heavy workloads like product catalogs or social feeds. The trade-off is added complexity and eventual consistency, so you only use it when the read load far exceeds the write load or when the consistency window is acceptable."
Common Mistakes Candidates Make
- Treating CQRS as a silver bullet – Applying it to a low-traffic CRUD app adds needless complexity.
- Confusing CQRS with Event Sourcing – Event sourcing is a way to store state as a sequence of events; CQRS is about separating read and write paths. You can use CQRS without event sourcing.
- Ignoring consistency requirements – Failing to discuss the eventual consistency window or how the UI handles stale data will raise red flags.
- Skipping the “why” – Interviewers expect you to justify the pattern based on read/write ratios, latency goals, or scaling constraints, not just to name it.
How to Practice This
- Pick a classic interview prompt (e.g., e-commerce catalog) and draw two separate boxes: one for the command side with an event log, and one for the query side with a denormalized store.
- Write a short script that walks through a command, the event propagation, and the query response, noting where latency and consistency differ.
- Use System Design AI’s canvas to sketch the full flow and ask the AI coach to review your explanation of CQRS.
Questions people ask
When should I suggest CQRS in an interview?
Suggest it when the problem emphasizes a read-heavy workload, strict read latency, or the need to scale reads and writes separately. It shows you understand workload patterns.
Does CQRS require event sourcing?
No. Event sourcing is one way to store commands as events, but CQRS only mandates separate read and write models. You can use a simple write DB and still have a distinct read side.
How do I handle stale reads in a CQRS design?
Acknowledge eventual consistency, describe UI cues like a refresh button, and note that critical paths can fall back to the write store for a strongly consistent read.
What operational overhead does CQRS add?
You must monitor the event bus, ensure idempotent consumers, handle replay of events, and keep two data stores in sync. Those are the main operational concerns.