What is CQRS (command query responsibility segregation)?

CQRS (command query responsibility segregation) is a design pattern that uses one model to change data (commands) and a separate model, often a separate store, to read it (queries).

Also called command query responsibility segregation, CQRS patternUpdated

CQRS stands for command query responsibility segregation. Most applications use one model for everything. The same Order entity and tables handle placing an order and showing the order history page. CQRS splits that into two:

  • The command side handles changes such as PlaceOrder or CancelOrder. It enforces business rules and returns little or nothing.
  • The query side answers reads such as "show this customer's orders with product names and delivery status". It never changes state.

Greg Young and Udi Dahan popularised the pattern in the late 2000s, and Young's "CQRS Documents" (2010) is the usual reference. It builds on Bertrand Meyer's older command-query separation (CQS) principle, which says a method should either change state or return data, not both. CQRS applies that idea to whole models instead of single methods.

How it works

In the simplest form, both sides share one database. Commands go through the domain model, and queries use plain SQL or views tuned for screens. Many teams in C# and .NET use a mediator library to route command and query objects to separate handlers. That is CQRS at the code level.

In the fuller form, the query side has its own store. Each change on the command side publishes an event or a CDC record. A projector consumes it and updates one or more read models: denormalised tables, a search index or a cache shaped for a particular screen. Reads then never touch the write database.

Example: a marketplace order history

A marketplace's write side keeps orders normalised in PostgreSQL across orders, order_items, shipments and refunds. The "My orders" page needs all four joined, plus seller names, and it gets 50 times more traffic than checkout.

With CQRS:

  1. PlaceOrder writes the normalised rows in one transaction and records OrderPlaced in an outbox.
  2. A projector consumes OrderPlaced, ShipmentDispatched and RefundIssued. It upserts one document per order into a read store:
{ "orderId": "ord_5521", "customerId": 42, "status": "dispatched",
  "items": [{ "name": "Steel bottle 1L", "seller": "Rajkot Steelware", "qty": 2 }],
  "totalPaise": 149900, "updatedAt": "2026-11-21T10:45:00Z" }
  1. The page reads one document by customerId, with no joins.

The trade-off is lag. For a moment after checkout, the read model may not show the new order. The UI handles this by showing the order from the command response, or by polling briefly. This is eventual consistency, and the product team has to accept it.

CQRS and event sourcing

They are often mentioned together but are separate choices. Event sourcing stores state as a log of events. Because you can't query an event log efficiently, event-sourced systems almost always need CQRS read models. CQRS, though, works fine with an ordinary relational write model.

When to avoid it

Martin Fowler warns that for most systems CQRS adds risky complexity, and that it should be applied to specific parts of a system, not the whole. Skip it when:

  • reads and writes use roughly the same shape of data
  • a read replica, a database view or a cache would solve the performance problem
  • the team can't support projectors, replays and lag monitoring

Use it for the few areas with heavy, differently shaped reads: dashboards, search, feeds and order history.

Read models often live in a search engine. See Elasticsearch vs OpenSearch vs Typesense, or our product engineering work.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call