The Command Query Responsibility Segregation (CQRS) pattern advises splitting an application into query and command parts.
A service should be either responsible for a query or command, but not both. The query side is responsible for returning the data that's been queried. The command side is responsible for performing some actions. Often, an action change the state of the application, such as creating, deleting, or updating stored resources.
The CQRS pattern fits well with a microservices-based architecture that splits various business functionalities into smaller services. It is easy to imagine one service providing various metrics about products while another service is used to update the products catalog.
We have to bear in mind that, with microservices, it can be challenging to keep all of the services consistent. For example, a change in a service that's responsible for creating a product, such as it being able to add a new feature, can result in changes in the query service. The query service now needs to return products with the newly added feature. If we keep the schema or resources consistent between services, the CQRS pattern can greatly help us design communication between services.
The need to keep microservices consistent between each other is an example of a pitfall that's encountered when designing microservices-based architectures. In the next section, we will explore other common pitfalls.