Implementing the command side
In this section, we will focus on implementing the command side of the application. This is where we expect all the business logic of the application to be implemented. Logically, it looks like the following figure:
Figure 5.2 – Traditional versus CQRS architecture
The high-level sequence on the command side is described here:
- A request to mutate state (command) is received.
- In an event-sourced system, the command model is constructed by replaying existing events that have occurred for that instance. In a state-stored system, we would simply restore state by reading state from the persistence store.
- If business invariants (validations) are satisfied, one or more domain events are readied with the intention to be published.
- In an event-sourced system, the domain event is persisted on the command side. In a state-stored system, we would update the state of the instance in the persistence store.
- The...