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: