Web apps & software

What is CQRS?

CQRS (Command Query Responsibility Segregation) is a design pattern that splits an application into a write side, which handles commands that change data, and a read side, which answers queries from models shaped specifically for fast reading.

The idea in plain terms

Most apps use one model for everything: the same tables and classes save an invoice and power the invoice list. CQRS says those jobs have different needs. Writing must enforce business rules (an invoice cannot be paid twice); reading must be fast and flexible (show overdue invoices by customer with totals). So the write side stores normalized data and validates commands, then publishes changes that update one or more read models, such as a denormalized table, a search index or a cache.

When it is worth it

  • Reads vastly outnumber writes and need very different shapes, as in dashboards and marketplaces.
  • Several views of the same data must stay fast, for example a dispatcher map, a driver history and a finance report.
  • You already use events or event sourcing and want projections built from them.

When it is not

For typical CRUD screens, CQRS doubles the moving parts. Read models lag slightly behind writes (eventual consistency), so a user may save something and not see it for a moment unless you handle that case. Start simple and introduce a separate read model only for the screens that actually struggle.

Questions, answered

No. Many teams start with separate read tables or views in the same database.

No. They are often combined, but either can be used without the other.

By the Stegnor team · Updated