Video in progress

When should you actually apply CQRS, and when is it needless complexity?

CQRS pays off when read and write loads, models or scale differ sharply. In plain CRUD, two models, synchronization and eventual consistency only add more bugs.

📖 Answer

The light form of CQRS is useful almost every time: in code, commands (which change state and return nothing or just an id) and queries (which only read) live in separate classes. PlaceOrderHandler and OrderSummaryQuery. One database, one transaction, just tidy code. On the query side you use direct SQL/projections instead of entities, so N+1 and excess mapping disappear.

The heavy form is a separate read model, often in a separate database (Elasticsearch, a denormalized table), updated through events. This is where the questions begin.

When it pays off:

  • reads outnumber writes a hundred to one and the read model has a completely different shape (search, aggregates, dashboards);
  • the write side has complex invariants and must stay normalized;
  • there are different read needs, and one model can't cover them all.

The cost:

  • eventual consistency: a user places an order, opens the list, and the order isn't there. You have to handle it in the UI or with a "read your own writes" mechanism;
  • rebuilding projections: when the schema changes you need a way to refill the whole read model from events;
  • projection lag has to be monitored.

A mistake I've seen often is thinking CQRS must come paired with event sourcing. They are independent. You can do CQRS with an ordinary database and CDC, and very few systems truly need event sourcing.

When deciding, I start with the light form, and only when the read side really is a bottleneck (measured, not guessed) do I add separate storage for that one read model.