How CQRS works
Reads and writes want different things — so give them different models.
CQRS (Command Query Responsibility Segregation) splits an application into a command model that handles writes and a query model that handles reads, often backed by separate data stores kept in sync via events. This lets you optimize and scale each side independently, at the price of extra complexity and eventual consistency — which is why it pairs so naturally with event sourcing.
One model becomes two
In a traditional design a single model handles both reading and writing, which forces awkward compromises: the same schema must serve complex transactional updates and fast, varied queries. CQRS splits responsibility down the middle into a command side for changes and a query side for reads. Each side can now be designed purely for its own purpose without fighting the other.
The command side
Commands express intent to change state — PlaceOrder, UpdateAddress — and are handled by the write model, which enforces business rules and validation before persisting. This side is typically normalized and optimized for consistency and correctness of writes. It returns little more than success or failure, because its job is to change the world, not to report on it.
The query side
Queries ask questions and never modify anything, so the read model is shaped purely for fast retrieval. It is often denormalized — pre-joined and pre-shaped to match exactly what screens need — so a page load becomes a single simple lookup instead of many expensive joins. Free from write concerns, the read side can be tuned aggressively for speed.
Keep the stores in sync
When the two sides use separate stores, a change on the write side must propagate to the read side. This is usually done asynchronously by publishing events that the read side consumes to update its views. The synchronization is what makes the read model eventually reflect every write, and it is exactly the seam where event sourcing plugs in.
Weigh the trade-off
Scaling reads and writes independently is a major win, especially for read-heavy systems, but CQRS adds real complexity and introduces eventual consistency between the two sides. It is therefore applied selectively — often to just the parts of a system that need it — rather than everywhere. Used well, and frequently paired with event sourcing, it turns a strained single model into two that each excel.
The problem with one model for everything
Most applications use a single model for both reads and writes: the same classes, the same schema, the same tables serve the command that updates an order and the query that lists a customer's orders. For simple systems this is exactly right — it's the least complexity for the job. But reads and writes are fundamentally different workloads, and forcing them through one model creates a quiet tension that grows with scale.
Writes care about consistency and correctness: validating business rules, enforcing invariants, and safely mutating state, usually against a normalized schema that avoids duplication. Reads care about speed and shape: returning data in exactly the form a screen needs, as fast as possible, often across many entities. A normalized schema that's perfect for writes forces reads to do expensive joins; a denormalized schema that's perfect for reads makes writes complicated and error-prone. One model cannot be optimal for both. CQRS — Command Query Responsibility Segregation — resolves the tension by refusing to compromise: it gives reads and writes each their own model.
Commands and queries — the core split
CQRS builds on a simple distinction that predates it, sometimes called *command-query separation*: every operation is either a command or a query, never both.
- A command is an instruction to *change* state —
PlaceOrder,CancelSubscription,UpdateAddress. It expresses intent, is handled by the write model, runs validation and business rules, and returns little more than success or failure. Its job is to change the world, not to report on it. - A query is a request to *read* state — "list my recent orders," "show this product page." It is handled by the read model, must never modify anything, and simply returns data.
The insight of CQRS is to take that logical separation and make it *architectural*: the command side and the query side become genuinely different components, with different models, and often different data stores. Once they're separate, each is free to be designed purely for its own responsibility — the write side for transactional integrity, the read side for retrieval speed — without either one dragging on the other.
Separate stores kept in sync
CQRS exists on a spectrum. In its lightest form, both sides share one database but use different models in code. In its fuller form — the version worth understanding — the command and query sides have separate data stores, each optimized for its workload.
The write store is typically normalized, tuned for consistent, correct updates. The read store is typically denormalized: the data is pre-joined and pre-shaped so that a query which would otherwise require joining five tables becomes a single, trivial lookup. You might even keep several read stores in different technologies — a document store for one view, a search index for another, a cache for a third — each purpose-built.
The obvious question is: if writes go to one store and reads come from another, how does the read side ever learn about changes? The answer is synchronization, and it's almost always asynchronous via events. When the write side commits a change, it publishes an event; the read side subscribes to those events and updates its views accordingly. This event-driven seam is the mechanism that keeps the two stores agreeing — and it's precisely where event sourcing slots in, because an append-only event log is a perfect, natural source of the events the read models consume. That's why the two patterns are so often discussed and deployed together, even though each can be used without the other.
Why bother — independent scaling
The headline benefit of full CQRS is that you can scale reads and writes independently, and that matters because real systems are wildly asymmetric. The overwhelming majority of applications read far more than they write — often by orders of magnitude. A product page might be viewed a million times for every time its price is edited.
With a single shared model, you're forced to scale the whole thing together: to serve more reads, you scale infrastructure that's also carrying the write load, which is wasteful and eventually hits limits. With CQRS, the read side and write side are separate components you can scale on their own terms. You can throw many cheap, replicated, denormalized read stores at a read-heavy workload while keeping a single, carefully-guarded write store, and neither decision constrains the other. Beyond raw scaling, the separation also improves clarity: the write model can focus entirely on rich domain logic and invariants (which is why CQRS is popular in domain-driven design), while the read models stay dumb, fast, and disposable — you can drop and rebuild a read view without touching the write side at all.
The cost, and when to reach for it
CQRS is not free, and applying it reflexively is a classic over-engineering trap.
The first cost is complexity. You now have two models, likely two data stores, and the synchronization machinery between them — more moving parts to build, deploy, monitor, and debug than a single CRUD model. The second, and more subtle, cost is eventual consistency. Because the read store is updated asynchronously after the write, there's a window where a query can return slightly stale data — a user might submit a change and not immediately see it reflected in their next read. Your product and UX have to tolerate that lag, or you need extra effort to paper over it.
Because of these costs, the right way to use CQRS is selectively. It is not an all-or-nothing, whole-application decision. You apply it to the specific parts of a system that actually benefit — a high-traffic, read-heavy area, a bounded context with genuinely divergent read and write needs, or a component where you're already event-sourcing — and leave the rest as simple CRUD. Reach for CQRS when: reads and writes have very different scaling or shape requirements; the domain has complex write-side business logic worth isolating; you need multiple specialized read views of the same data; or you're already using event sourcing and want clean, independent read models. Avoid it when a straightforward shared model would do — because in that case the extra complexity and consistency headaches buy you nothing. Used with that judgment, CQRS turns one overloaded model into two that each do their job exceptionally well.
CQRS separates the command (write) model from the query (read) model — two paths, not one shared model.
Commands change state and return little; queries read state and never change it.
The two sides often use separate data stores, each optimized for its workload (normalized writes, denormalized reads).
The read store is kept in sync with the write store, usually asynchronously via events.
You can scale reads independently of writes — most systems read far more than they write.
The cost is added complexity and eventual consistency, so it's used selectively, not everywhere.
Quick quiz
What does the 'C' and 'Q' split in CQRS actually separate?
Why does CQRS typically introduce eventual consistency?
What is event sourcing
Instead of storing where you are, store how you got there.
Key terms in domain-driven design
A shared language and a toolkit of patterns for modeling complex business domains.
How Apache Kafka works
A distributed commit log that decouples who produces data from who consumes it.
Best practices for microservices
Splitting a system into services only pays off if you follow the rules that keep them independent.