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 – heavy writes and heavy reads compete for the same database’s CPU, I/O, cache and indexes, so a burst of one slows the other.
- 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, every index you add for browsing and search slows each write, and heavy browsing competes with updates for the same database’s CPU and I/O.
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 and, in one database transaction, updates a write-optimized store (often a relational DB) and inserts anItemAddedrow into an outbox table. The command returns once that transaction commits; writing to the database and to Kafka as two separate steps would let a crash leave one without the other. - Event propagation – A relay (or change data capture) publishes the outbox row to a message broker such as Kafka. 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 answers are to keep a single model for that data, or to give the user read-your-writes: read from the write store right after their own command, or have the command return a version and make the query wait until the read view has reached it.
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.
- Sketch the full flow on paper or a whiteboard, then walk through it aloud and mark every place a read can be stale. For the step that publishes events from the command side, read the free worked design Transactional Outbox.
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 stores state as the sequence of events that changed it, but CQRS only requires 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.