Implementing the query side
In Chapter 5, Implementing Domain Logic, we examined how to publish events when a command is successfully processed. Now, let’s look at how we can construct a query model by listening to these domain events. Logically, this will look something like the following diagram:
Figure 7.2 – The CQRS application – the query side
For a detailed explanation of how the command side is implemented, please refer to the Implementing the command side section in Chapter 5, Implementing Domain Logic.
The high-level sequence on the query side is described here:
- An event listening component listens to these domain events published on the event bus.
- It constructs a purpose-built query model to satisfy a specific query use case.
- This query model is persisted in a datastore optimized for read operations.
- This query model is then exposed in the form of an API.
Note how there can exist more than one query...