liveBook · Manning

Analytical query

As explained in Microservices Patterns, Second Edition

A query that derives summary or analytical results from stored data, often across many records.

An analytical query computes an aggregate, such as an average or total, across many entities. In a CQRS view, precompute the aggregate when calculating it for every query would be too slow because of query frequency or data size. section 13.3 section 13.3.2

Average delivery time

For an average delivery time by restaurant and day, store a sum and count rather than an average. A DeliveryDelivered event identifies the record to update; queries can then read the aggregate without scanning every delivered order. section 13.3.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains when to precompute aggregates and how event handlers maintain sums and counts as events arrive.
Examples
Uses average delivery time per restaurant and day, represented by a precomputed sum and count.
What you can do after
Build a CQRS view that serves costly analytical queries from aggregates maintained by events.
How it connects
Connects analytical queries to CQRS views, event handlers, and view schemas.

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.