liveBook · Manning

Precomputation

As explained in Microservices Patterns, Second Edition

The calculation of values in advance so they can be stored and retrieved rather than recomputed for each query.

Precalculation computes values in advance so they can be stored and retrieved rather than recomputed for each query. In a CQRS view, deciding what to precompute is part of designing a schema that serves queries efficiently without making event-handler updates inefficient. section 13.3.2

Use precomputation when query efficiency matters, weighing its benefits against the work of keeping the view updated.

  • For large datasets or high query volumes, precomputation and related schema optimizations can help meet query SLOs and control costs. section 13.3
  • For small datasets queried infrequently, a normalized relational schema with joins may be simpler and adequate. section 13.3

Restaurant proximity query

A view schema can store a restaurant’s latitude and longitude to support a proximity filter, even though those values are not returned in the query result. section 13.3.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains the schema decision and its scale-related trade-offs, but does not detail a precomputation procedure.
Examples
Illustrates query-supporting restaurant latitude and longitude for a proximity filter.
What it assumes
Assumes a CQRS view with queries and event-handler updates as the setting for schema decisions.
What you can do after
Evaluate whether query scale justifies precomputation and related schema optimizations over a simpler normalized design.
How it connects
Connects precomputation to CQRS views, denormalization, database indexes, and query design.

Also explained in

Compare how 3 books explain precomputation →

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.