The first time I implemented CQRS for real was because a single data model could no longer keep up: writes needed strict transactional integrity, and reads needed to serve thousands of queries per second with filters that the transactional model wasn't designed to handle well. Trying to make a single table, a single schema, serve both goals had us fighting the database instead of solving the business problem.
What is CQRS?
CQRS (Command Query Responsibility Segregation) is a pattern that separates the model that receives commands (writes) from the model that answers queries (reads). Each side is designed, optimized, and scaled on its own.
What almost nobody tells you when they pitch it in a meeting is the real price of that separation. In this article we cover what it is, how it works, what it costs, and when it isn't worth it.
The command side validates business rules and persists the change as the source of truth. The query side maintains one or more "projections" — copies of the data, optimized for reading, that get updated asynchronously based on what happened on the command side.
CQRS is not splitting folders into command and query
It's a common mistake. Having CreateOrderCommand and GetOrderQuery classes is not CQRS if both
still read and write the same model. That's good code organization, useful and recommended, but a
different thing. CQRS starts when the read and write models are actually separate.
It's also not the same as Event Sourcing. Event Sourcing stores the sequence of events as the source of truth; CQRS only separates the models. They're often combined, but you don't need one to use the other.
How it works: commands, events, and projections
// Command side: validates and persists the intent
async function handleCreateOrder(cmd: CreateOrderCommand) {
const order = Order.create(cmd.customerId, cmd.items) // business rules here
await orderRepository.save(order)
await eventBus.publish(new OrderCreatedEvent(order.id, order.items))
}
// Query side: updates by reacting to the event, not the command
async function onOrderCreated(event: OrderCreatedEvent) {
await orderSummaryReadModel.upsert({
orderId: event.orderId,
itemCount: event.items.length,
status: 'created',
})
}
Nothing exotic. The complexity isn't in the code, it's in what happens between those two functions.
The price: eventual consistency
Between when the command is saved and when the read projection is updated, there's a window of time —almost always milliseconds— where the system is in an inconsistent state: the write has already happened, but if you query the read view you won't see it reflected yet. That's eventual consistency, and it's not an implementation flaw: it's a direct consequence of separating the models.
The mistake I see most often is treating that window as if it didn't exist, until a user creates an order, immediately refreshes the page, doesn't see it, and opens a support ticket convinced that the system lost their order. The system didn't lose anything. The architecture simply didn't warn anyone that there was a delay.
A ladder, not a leap
Before buying the full package, climb one step at a time and stop at the one that solves your problem:
- A single, well-indexed model. It solves more cases than people think.
- Separate models in the same database: views, summary tables, or a read replica, updated in the same transaction. There is no eventual consistency yet.
- Asynchronous projections fed by events. This is where eventual consistency appears.
- Separate stores for each side, for example a relational database for writes and a search engine for reads.
When it's worth it (and when it's over-engineering)
CQRS makes sense when the read pattern and the write pattern are genuinely different: high read frequency with highly varied query shapes, writes that require heavy business validation, or the need to scale reads and writes completely independently.
| Scenario | Worth it | Not worth it |
|---|---|---|
| High read frequency (thousands of QPS) | ✅ Separating models scales better | ❌ If a single table works fine below 100 QPS |
| Varied read shapes (multiple indexes, aggregations) | ✅ Optimized projections | ❌ If queries are always the same |
| Heavy writes (complex validations) | ✅ The delay is tolerable | ❌ If it's simple CRUD |
| Independent scaling (different R/W volumes) | ✅ Separation has a purpose | ❌ If they scale evenly |
| Frequent new read types | ✅ Projections are flexible | ❌ If the schema is stable |
It doesn't make sense for a standard CRUD where reading and writing the same model works perfectly well. I've seen teams drop full CQRS — with an event bus, separate projections, and distinct storage for each side — into systems that would have been just as well served by a table and an index. The question I ask myself before proposing it isn't "is this a valid pattern?", it's "does the problem I have justify the operational complexity I'm about to introduce?".
An example on AWS
One way to put it together, not the only one, for a service with strict writes and many reads with varied filters (think of an orders or transfers service):
- Commands: API Gateway and Lambda validate the business rules and write to Aurora PostgreSQL, which is the source of truth.
- Transactional outbox: the event is saved in the same transaction as the change, in an
outboxtable, and a separate process publishes it to EventBridge or SQS. That avoids the classic "I saved the data but never published the event". - Projections: an idempotent consumer Lambda updates the read models: DynamoDB for key lookups and OpenSearch for searches with varied filters.
- Queries: another API behind API Gateway reads only from the read models.
Every piece adds operations: queues with retries and a dead-letter queue (DLQ), monitoring of projection lag, event replay. That's the operational complexity I mentioned above. The AWS Prescriptive Guidance on CQRS describes the pattern in more detail.
How to live with the inconsistency window
If you decide it's worth it, there are reasonable ways to keep eventual consistency from feeling like a bug:
- Optimistic UI: update the interface with the expected result as soon as the command is accepted, without waiting for the read projection to confirm.
- Version tokens: attach the version of the data the client saw to the command, so the system can decide whether the state read is stale before accepting a change.
- Idempotent projections: design the event consumer so that processing the same event twice doesn't break anything — retries and duplicate deliveries are the norm, not the exception, in event-based systems. It's the same idea as designing for failure.
- Communicate the delay when it matters: if there's an operation where the user needs to see their change reflected immediately, consider reading directly from the write model for that specific case, instead of forcing everything through the eventual projection.
Frequently asked questions
Does CQRS require Event Sourcing?
No. CQRS separates the read and write models; Event Sourcing stores events as the source of truth. They're independent, although they often show up together.
Does CQRS mean having two databases?
Not necessarily. It can be the same database with separate tables or views, a read replica, or distinct stores. Pick the lowest step of the ladder that solves your problem.
What happens if a projection fails or falls behind?
If the consumer is idempotent and you keep the events, it retries safely and the projection can be rebuilt by replaying them. Measure projection lag and alert when it exceeds what your business tolerates.
When should I not use CQRS?
In a standard CRUD, with low read load, or with a stable schema. If you're unsure, write the decision down in an ADR: the operational cost becomes explicit and easier to revisit later.
CQRS doesn't solve the consistency problem, it makes it explicit. And in architecture, making explicit a trade-off that already existed —but was hidden— is almost always worth more than pretending it doesn't exist.
To place CQRS among other patterns, see architectural patterns and design patterns and the BFF pattern. For the classic reference, Martin Fowler's explanation and the Azure Architecture Center are good starting points.


