Skip to main content

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.
info

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:

  1. Open Usecase Details Menu:

    • Click on a Usecase on the map to access its details.
  2. Open the Usecase Management Menu:

    • Click the Hamburger Menu icon (Hamburger icon) on the very left of the Usecase Details Menu. This action opens an additional menu on the left side.
  3. Select a Source Readmodel:

    • Choose a Source Readmodel from the dropdown menu.

    Codebricks Planner with opened Usecase Details with Usecase Management menu. Add Source Readmodel is highlighted.

note

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.

info

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 the SELECT statement to filter the results.

    Codebricks Planner with opened Usecase Details on a source readmodel.

Removing a Source Readmodel

To remove a Source Readmodel, follow these steps:

  1. Open Usecase Details Menu:

    • Click on a Usecase on the map to access its details.
  2. Open the Usecase Management Menu:

    • Click the Hamburger Menu icon (Hamburger icon) on the very left of the Usecase Details Menu. This opens an additional menu on the left side.
  3. Remove the Source Readmodel:

    • Click the small x on the chip of the Source Readmodel you wish to remove.

    Codebricks Planner with opened Usecase Details with Usecase Management menu. Remove Source Readmodel is highlighted.