A view service maintains a query-oriented copy of provider data. It consumes provider events to update a view database and serves system queries from that prepared view. section 13.2.1
The service handles two paths:
- Update: event handlers consume provider events and use the view repository to update the view database. section 13.2.1
- Query: query handlers use the view repository to retrieve results from the view database. section 13.2.1
When designing a view, choose whether to reuse an existing one or create a new one, and determine its database, schema, repository operations, and required provider events. Reuse saves infrastructure, but unrelated queries can make a view less cohesive and harder to evolve. section 13.3
Event-driven updates add implementation and coordination work: handlers must account for duplicate or out-of-order events, idempotency, and replay. Separate view stores can also require teams to work with multiple data technologies and maintain event contracts. section 13.2.3
Figure 13.4 Because it takes time for an event to flow from the provider service to the CQRS view, a client is not guaranteed to be able to read its own writes. A query might not return data that is up to date.
Events take time to reach a view, so a query may not immediately reflect a client's write. section 13.2.3
