Querying Readmodels
In event-driven architectures, querying Readmodels is essential for accessing and utilizing the data that has been projected into a Readmodel. This access allows for additional context in business decisions, enrichment of other Projections, or simply retrieving information via a Query API.
Readmodels vs. Source Readmodels
We distinguish between Readmodels and Source Readmodels:
- Readmodels: These are schemas modeled in a Projection usecase. They are written by the Usecase and can be modified within that Usecase.
- Source Readmodels: These are schemas modeled across various Usecases. They are read-only and are used for querying information by a Usecase without modifying them.
Understanding this distinction helps in designing a flexible and maintainable system. Readmodels are writable and updated based on events, while Source Readmodels are read-only and provide consistent data access across Usecases.
Adding a Source Readmodel
To add a Source Readmodel, follow these steps:
-
Open Usecase Details Menu:
- Click on a Usecase on the map to access its details.
-
Open the Usecase Management Menu:
- Click the Hamburger Menu icon (
) on the very left of the Usecase Details Menu. This action opens an additional menu on the left side.
- Click the Hamburger Menu icon (
-
Select a Source Readmodel:
- Choose a Source Readmodel from the dropdown menu.
You can query Source Readmodels only from the same aggregate. This ensures a fine-grained modeling approach, allowing maximum flexibility for changes and potential rebuilds of individual Readmodels. As a rule of thumb, use one Readmodel for one specific purpose.
For Projection Usecases, you must also specify which event needs this information for a projection.
Define the Query Conditions
Specify the conditions to retrieve the desired Readmodel entries:
-
Query Result Amount: Indicates whether the result should be a singular entry or an array of entries.
-
Query Condition: Defines the
WHERE
conditions in theSELECT
statement to filter the results.
Removing a Source Readmodel
To remove a Source Readmodel, follow these steps:
-
Open Usecase Details Menu:
- Click on a Usecase on the map to access its details.
-
Open the Usecase Management Menu:
- Click the Hamburger Menu icon (
) on the very left of the Usecase Details Menu. This opens an additional menu on the left side.
- Click the Hamburger Menu icon (
-
Remove the Source Readmodel:
- Click the small x on the chip of the Source Readmodel you wish to remove.