liveBook · Manning

Distributed query execution

As explained in Microservices Patterns, Second Edition

A data-retrieval operation whose required data resides across multiple services.

A distributed query retrieves information owned by multiple services. Because each service controls its data and transaction boundary, the query cannot use cross-service database joins or one distributed ACID transaction; services must collaborate through APIs or another service pattern. section 12.0 section 12.1.5

Finding an order

A findOrder() query may combine order details and status from the Order Service, preparation status from Kitchen, delivery information from Delivery, and payment status from Accounting. Each service supplies its part through its API. section 12.1.5

Figure 12.4 Implementing a system query, such as findOrder(), in a microservice architecture can be challenging because the needed information is scattered across multiple services, yet neither distributed joins nor distributed transactions can be used.
FindOrderQueryOperationMicroservices

Shows why scattered data, unavailable cross-service joins, and unavailable distributed transactions make the query challenging. section 12.1.5

Choose a collaboration pattern according to query cost and runtime requirements:

  • Use API Composition as the simplest viable option: an API composer synchronously calls provider services and combines their results. It can reside in a client, gateway, Backend-for-frontend, or standalone service. section 12.4
  • Prefer CQRS when composition would require too many network round trips, large data transfers, or expensive in-memory joins. A queryable view can pre-join data and avoid direct runtime dependence on provider services. section 12.4 section 13.2.2

Composition runs independent local transactions, so results may be inconsistent across providers. Use circuit breakers, time limits, and fallbacks to improve availability, and invoke providers concurrently where possible to reduce latency. Distributed queries do not provide a strongly consistent cross-service view. section 12.4 section 7.5.1

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains service boundaries, API Composition, trade-offs, and CQRS alternatives without detailing their full implementations.
Examples
Uses findOrder() to combine order, kitchen, delivery, and payment data from four services.
What it assumes
Assumes familiarity with microservices, service-owned data, and service APIs.
What you can do after
Apply API Composition for suitable queries or choose CQRS when composition becomes inefficient.
How it connects
Connects API Composition and CQRS with microservices, service APIs, and eventual consistency.

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.