CQRS Is a Domain Boundary, Not a Framework
CQRS separates the model for writing from the model for reading – a domain decision, not an installable framework. When the boundary pays off, how to start small and which mix-ups get expensive.
Every application asks its data two questions: What should change? And what should be displayed? Most systems answer both with the same model – the same entities, the same mapping, the same objects. CQRS answers them with two.
Still, the most common follow-up question about the acronym – Command Query Responsibility Segregation – is about tools: Which library, which package? You’ll look for that in vain. The boundary between the write model and the read model runs through the domain, not through the dependency tree. What CQRS is, what it explicitly isn’t, when the separation pays off and where the most expensive mistakes lie – that’s what this article is about. The result is less spectacular than the acronym promises, and that’s exactly the good news.
Where the term comes from#
CQRS stands for Command Query Responsibility Segregation. The core is a single idea: you use a different model to change information than the model you use to read it. What is a single conceptual model in classic systems – the same entities you write and read with – is deliberately split into two separate models. One for commands, that is, for intentions and changes. One for queries, that is, for views and queries.
Martin Fowler sums up the reasoning: for many problems, particularly in more complicated domains, a shared conceptual model for commands and queries leads to a model that does both jobs worse than two specialized models would. Fowler himself first heard the term from Greg Young, who coined and fleshed out CQRS around 2010.
What matters is the distinction from an older principle that CQRS is often confused with: Command Query Separation, CQS for short, by Bertrand Meyer. CQS separates at the method level – a method is either a command that changes state and returns nothing, or a query that returns a value without changing state. CQRS lifts exactly this principle to the architecture level: no longer two kinds of methods, but two separate object models. Conceptually, CQRS builds on CQS, but it works at a much coarser grain.
The two sides have a different shape#
The write side and the read side don’t just have different jobs; they have a different shape. That’s not a cosmetic observation but the actual reason for the separation.
The write side works with a rich domain model. This is where the invariants live, the domain rules that decide whether a change is allowed at all. A command is the expression of a domain intention – phrased imperatively, nameable, rejectable. DeactivateInventoryItem isn’t a record update but a statement: “I want to deactivate this item.” That fits perfectly with task-based UIs, in which users express intentions instead of filling in form fields.
The read side, by contrast, doesn’t want to decide anything. It wants to display. Its natural shape is flat DTOs tailored to presentation – often a direct projection of what appears on screen. Rules, invariants, behavior: the read side needs none of that. You only force it into a rich domain model because that model happens to exist already.
This is exactly where CQRS comes in. Instead of squeezing both sides into one model that serves neither of them well, you give each side the shape it deserves.
flowchart LR
Client -->|Command| CommandHandler
CommandHandler --> WriteModel
WriteModel --> Store[(Store)]
Client -->|Query| QueryService
QueryService --> ReadModel
ReadModel --> StoreNote: both paths can use the same store. More on that in a moment – it’s more important than it looks.
A look at the write side#
Illustrative, in TypeScript. The write side receives a command, loads the rich write model, lets it enforce the domain rule and saves.
interface DeactivateInventoryItem {
itemId: string;
reason: string;
}
class InventoryCommandHandler {
constructor(private readonly repo: InventoryItemRepository) {}
handle(cmd: DeactivateInventoryItem): void {
const item = this.repo.findById(cmd.itemId); // rich write model
item.deactivate(cmd.reason); // domain rule enforced here
this.repo.save(item);
}
}
The interesting part is in the middle line. item.deactivate(cmd.reason) is where the domain logic sits. Whether an item may be deactivated, whether a reason is mandatory, whether an already deactivated item rejects the command: the domain object decides that, not the handler. The command handler is deliberately thin. It orchestrates; it doesn’t decide.
And a look at the read side#
The read side completely ignores this rich model. It queries a view optimized for display and returns a flat DTO.
interface InventoryListItemDto {
id: string;
name: string;
isActive: boolean;
}
class InventoryQueryService {
constructor(private readonly readDb: ReadDatabase) {}
listActiveItems(): InventoryListItemDto[] {
return this.readDb.query(
"SELECT id, name, is_active FROM inventory_view WHERE is_active = true",
);
}
}
No repository, no domain object, no invariant. Just a query against a view that delivers exactly what the list needs. You could object that raw SQL sits directly in a service here – for the read side, that’s often exactly right. There is nothing to protect, no rule to uphold. The detour through a rich model would be pure ceremony.
The point it all comes down to: these two classes don’t know each other. They share no common model. They are two separate answers to two separate questions. That’s CQRS.
Start small – one store is enough#
And now comes the part that surprises most people. Nothing in the two examples above requires two databases. InventoryItemRepository on the write side and readDb on the read side can point to the same database. Fowler puts it unmistakably: the models can share the same data store – the database then acts as the communication between the two models.
This means: you can practice CQRS without introducing a single additional store. A rich write model that works against the tables. A view that the read side queries directly. Both in the same database. You get the domain separation without buying into a second data store and its consequences.
On one project, we had put off the pattern for years because it was considered unaffordable – too much infrastructure, too much operations. The concern was based on a mix-up: CQRS was equated with one specific, elaborate expansion stage of CQRS. Separating the models is cheap. What costs money is separate stores, and they are optional.
What CQRS is – and what it isn’t#
Because so many half-truths gather around the term, here is a clear sorting. CQRS is:
- the domain separation of the write model and the read model,
- a pattern for selected bounded contexts,
- combinable with Event Sourcing when the domain justifies it,
- practicable with a single store from the start.
CQRS is not:
- a framework or a library,
- a synonym for Event Sourcing,
- an obligation to have two databases,
- a system-wide architecture standard that you roll out everywhere.
Most of the trouble I see in reviews hinges on this second list.
The three most expensive mix-ups#
The first is trying to use CQRS everywhere. It’s a minority case, not a default. Fowler explicitly warns that for most systems CQRS adds risky complexity and that you should be very cautious about using it. The separation belongs in a single bounded context where the domain justifies it – not in every module, not in every entity. If you roll out CQRS system-wide, you pay the cost of the separation everywhere and reap the benefit only in the few places where the models really drift apart.
The second is confusing CQRS with Event Sourcing. That’s the most common mix-up of all, and I understand where it comes from – the two almost always appear together in talks and examples. But they are independent patterns. Event Sourcing is a decision about persistence: instead of storing the current state, you store the sequence of events that led to it. CQRS is a decision about models: writing and reading get separate models. You can have either without the other. Vaughn Vernon’s IDDD samples do show contexts that combine Event Sourcing and CQRS – but even there, it remains a deliberate combination of two patterns, not a definition in which one contains the other. If you say CQRS and mean Event Sourcing, you’ll constantly talk past each other in discussions.
The third is introducing two databases too early. Separate read and write stores are an optional, later optimization – usually driven by asymmetric load, when you want to scale the read side and the write side independently. If you introduce them too early, you take on two costs before any need has been proven: the synchronization effort between the stores and, more seriously, eventual consistency. From the moment the read store lags behind the write store, users may see data that is already outdated. That’s a domain problem, not a technical detail – and you should only take it on when you have a concrete reason for it.
This is what that expansion stage would look like – one you deliberately take only when the load demands it:
flowchart LR
CommandHandler --> WriteModel
WriteModel --> WriteStore[(Write Store)]
WriteStore -.->|projection<br/>eventual consistency| ReadStore[(Read Store)]
QueryService --> ReadStoreThe dashed arrow is the price. There is now a projection between the write store and the read store, and with it a delay. As long as this arrow isn’t needed, it shouldn’t exist.
When the boundary really pays off#
After all these warnings, the constructive side: there are situations in which CQRS is the right answer. I see essentially three.
The first is complex domains in which a shared model serves neither side well. When the write model is barely queryable because of all its invariants and behavior, and the read side painfully works its way through this model to produce simple lists, both are fighting the same structure. The separation frees both.
The second is asymmetric load. Many systems read orders of magnitude more often than they write. Separate models – and, in the expansion stage, separate stores – let you scale the read side independently without touching the write side.
The third is task-based UIs. When the UI thinks in intentions anyway – “deactivate item,” “cancel order” – instead of in CRUD forms, the command side of CQRS is already in the air. You just have to name it.
All three criteria have the same origin: the structure follows from the domain, not from the wish for a modern diagram. CQRS isn’t a goal. It’s an answer – and only right where the domain asks the matching question.
Conclusion#
If you understand CQRS as a framework, you’re looking in the wrong place. There is nothing to install. The only decision that counts is a domain decision: Does this domain benefit from writing and reading getting different models? If yes, you draw the boundary – small, with a single store, without Event Sourcing, in a single bounded context. If no, you leave it, and that’s the more common case.
The separate databases, the projections, eventual consistency – all of these are later, optional expansion stages that you take when the load demands it, and not earlier. Equating CQRS with these expansion stages is the mistake that makes the pattern expensive and intimidating. In its essence, it’s the opposite: an unspectacular, cheap, domain-driven separation. Two questions, two models. That’s all you need to get started.
Further reading#
- Slide deck on this topic: https://slides.mikebild.dev/introduction-cqrs-event-sourcing.en.html
- Martin Fowler, “CQRS”: martinfowler.com/bliki/CQRS.html
- Martin Fowler, “CommandQuerySeparation”: martinfowler.com/bliki/CommandQuerySeparation.html
- Greg Young, “CQRS Documents” (PDF): cqrs.wordpress.com
- Vaughn Vernon, “Implementing Domain-Driven Design,” chapter 4 (Architecture / CQRS), and the IDDD_Samples
- My own talk material “CQRS + Event Sourcing” (SlideShare), which some of the examples shown here come from
Revised and translated from German with the help of AI.