...

/

Command and Query Responsibility Segregation

Command and Query Responsibility Segregation

Explore the command and query responsibility segregation (CQRS) pattern combined with event sourcing for enhanced application performance.

Command and Query Responsibility Segregation (CQRS) is a simple pattern to define. Objects are split into two new objects:

  • One is responsible for commands. 

  • One is responsible for queries.

Press + to interact
Applying CQRS to an object
Applying CQRS to an object

The above figure demonstrates just how simple the concept might be, but it’s important to observe its practical details. The definitions for command and query are the same as they are for Command-Query Separation (CQS):

  • Command: Performs a mutation of the application state.

  • Query: Returns application state to the caller.

Note: In CQRS, just as it is in CQS, an action can either be a command or a query but not both.

The problem being solved

The domain models we’ve developed with the help of domain experts may ...