Command and Query Responsibility Segregation (CQRS) pattern day by day gaining its popularity and recently found reference on Official Microsoft.
The words Command, Query, Responsibility and Segregation well define the CQRS.
Which says, We should segregate operations by using separate interface, which can maximize performance, scalability and security.
Benefits:
Implementation of CQRS lead to more complex application design but it also suit best for the robust application design.
Let's have a look on simple design
Customer using
>------Client App using
>-----------Query to Get result,or
>-----------Command to Post and Patch etc to Add/Update data by using an
>-------------------------Web Api which have separate (DotnetCore webapi)
>---------------------------------------Validation layer (FluentValidation)
>----------------------------------------Command/Query handler to implement business logic MediatR)
<------------Send response back to client app
Above implementation could be found in GitHub Repo
Where we used
The words Command, Query, Responsibility and Segregation well define the CQRS.
Which says, We should segregate operations by using separate interface, which can maximize performance, scalability and security.
Benefits:
- Independent scaling
- Optimized data schemas.
- Security
- Separation of concerns
- Simpler queries
Implementation of CQRS lead to more complex application design but it also suit best for the robust application design.
Let's have a look on simple design
Customer using
>------Client App using
>-----------Query to Get result,or
>-----------Command to Post and Patch etc to Add/Update data by using an
>-------------------------Web Api which have separate (DotnetCore webapi)
>---------------------------------------Validation layer (FluentValidation)
>----------------------------------------Command/Query handler to implement business logic MediatR)
<------------Send response back to client app
Above implementation could be found in GitHub Repo
Where we used
- DotnetCore
- EntityFrameworkCore
- MsSql and InMemoryDatabase, As storage based on configuration.
- FluentValidation, To implement model validation.
- MediatR, To implement CQRS.
- Automapper, To project object.