CQRS - When to use and why to use?

Asked

Viewed 1,041 times

8

What are the advantages of using the CQRS (Command/Query Responsibility Segregation) standard? What would be the disadvantages ?

1 answer

3


In short, CQRS is useful and recommended in complex domain scenarios or high-performance applications.

Phrasing Microsoft documentation when compared to conventional CRUD model:

Compared to the single data model used in based systems in CRUD, the use of separate update and query templates for the data in CQRS-based systems simplifies design and implementation. However, one disadvantage is that, unlike CRUD projects, CQRS code cannot be generated automatically using mechanisms of scaffolding.

So one of the biggest advantages is improved performance in complex applications and one of the biggest drawbacks is the possible increase in complexity of the code that represents the model. However, CQRS is not recommended in all scenarios.

Recommended scenarios:

  • Collaborative domains with parallel operations in the same data model.
  • Task-based user interfaces divided into several steps
  • Systems where the amount of data read is much higher than the write number
  • Scenarios where the business rule is changed frequently
  • Integration between systems, where the failure of one cannot stop the other

Scenarios not recommended:

  • Domains with simple business rules (for example CRUD-based applications)

In addition, according to Martin Fowler’s recommendations, the CQRS standard should be applied to parts of a system and not to it as a whole. Trying to implement this standard in a system whose complexity is not compatible will only considerably decrease the productivity and complexity of development. Also consider the team’s experience with DDD, as an immature team regarding the correct implementation of rich domains can be disastrous in trying to implement CQRS.

There is no difference between implementing this standard with. NET Core or other framework or language, the considerations on using (or not) are not limited to a technical issue.

Sources:

Microsoft documentation: https://docs.microsoft.com/pt-br/azure/architecture/patterns/cqrs

Martin Fowler: https://martinfowler.com/bliki/CQRS.html

  • Thanks for the excellent reply. It helped a lot :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.