liveBook · Manning

View service

As explained in Microservices Patterns, Second Edition

A view service is a service that maintains and serves a query-oriented view of data.

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

Events take time to reach a view, so a query may not immediately reflect a client's write. section 13.2.3

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains service responsibilities, update and query paths, and choices for the database, repository, and provider events.
Examples
Uses an Order History Service whose view database supports findOrderHistory() using events from four provider services.
What you can do after
Evaluate and design a view by deciding whether to reuse an existing one and selecting its database, schema, repository operations, and provider events.
How it connects
Connects CQRS views with provider events, event handlers, query handlers, repositories, and view databases.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.