Implementing the CQRS pattern
CQRS stands for Command Query Responsibility Segregation. We can apply CQRS in two ways:
- Dividing requests into commands and queries.
- Applying the CQRS concept to a higher level, leading to a distributed system.
We stick with the first one here and tackle the second definition in Chapter 16, Introduction to Microservices Architecture.
Goal
The goal is to divide all requests into two categories: commands and queries.
- A command mutates the state of an application. For example, creating, updating, and deleting an entity are commands. In theory, commands do not return a value. In practice, they often do.
- A query reads the state of the application but never changes it. For example, reading an order, reading your order history, and retrieving your user profile are all queries.
Dividing operations into mutator requests (write/command) and accessor requests (read/query) creates a clear separation of...