Introduction to Command Query Responsibility Segregation
This pattern is based on the idea of command-query separation (CQS). So, according to CQS, we have to divide our command and query separately to make the system more reactive and robust. This command means the query to write something into the database to change the state of the domain, and the query means ready only query that doesn't change the state of the domain. These queries are based on the ready on access either from another database or somewhere in the cache. Let's look at the following:
- Commands, changing state of the system
- Queries, getting some information from the system
The CQRS naturally fits with some other architectural patterns, such as event-based programming models. It's common to see CQRS systems split into separate services communicating with event collaboration. This allows these services to easily take advantage of Event Sourcing.
This architectural pattern improves the performance of a distributed application where...