Skip to main content
Now that we have configured our write path using the in-memory event store, we want to construct a read-side query view. This allows us to display active balances or summaries on our user interface. To do this, we implement a Read Model and a Projection.

1. Defining the Read Model State

First, define the structure of the data you want to query. This is a query-optimized state. For our bank account dashboard, we want a simple map associating account IDs with their current total balance:

2. Implementing the Projection Trait

Next, implement the Projection trait for your read model. This specifies how our database view is updated whenever a new event envelope is committed to the store:
By maintaining this projection, we denormalize event records into a simple, high-speed key-value map, allowing client requests to resolve balances instantly.