CQRS, do not confuse with SPQR

Command Query Responsibility Segregation (CQRS) rule says that there should be different methods for modifying and read data. And has nothing to do with SPQR. Instead of one model you have two models/sides.

read and write sides

You have two sides: (1) write side is responsible for executing the domain logic (protecting invariants, storing data), it’s the source of truth; (2) read side (with separate data store and models) is optimised for reads.

There are plenty of advantages of that solution;

  1. It is easy to fetch data because we have dedicated and optimised for reading read models.
  2. Fetching is faster because we have optimised for reading read models.
  3. Read models can be independently scalable.
  4. Read models are easier to change.
  5. We have less methods in each models (having one ring to rule them all brings always troubles).
  6. Less responsibility of one model make it (especially write models) easier to test.
  7. Having write models allows you to focus on proper modelling of the domain instead of making compromises with need of fast reading.

Of course, there are two sides of every story. SQRS has also disadvantages.

  1. It needs developer’s mindset switching, you need to start thinking in two models.
  2. You will need more infrastructure.
  3. Write operation can be slower (because of the need to build read side), but this can be mitigated by eventual consistency.

Related Posts