liveBook · Manning

Chapter 12: Using the API Composition pattern to implement system queries

What you will learn in chapter 12 of Microservices Patterns, Second Edition

The introduction explains why queries spanning multiple services need application-level collaboration rather than database-level joins or distributed transactions.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why queries spanning multiple services need application-level collaboration rather than database-level joins or distributed transactions.

Key terms: distributed system queries, ACID transaction boundary, database-level joins, service collaboration patterns, API Composition, CQRS

12.1 The challenge of querying in the microservice architecture

Introduces the challenges of querying data across microservices and previews the approaches covered in the section.

12.1.1 System queries typically support the UI

The section uses FTGO’s Order Details view to show why a UI query should return information from multiple subdomains without making the frontend query each one separately.

Key terms: Order Details view, system queries, subdomains, single system query, findOrder(), network round trip

12.1.2 The findOrder() system query

This section defines the findOrder() system query and notes that its implementation depends on the application’s architecture.

Key terms: findOrder(), orderId, OrderDetails, GET /orders/{orderId}

12.1.3 Why system queries need to be transactional

This section explains why read-only system queries need isolation, how consistency applies within one statement and across multiple statements, and why database isolation defaults matter.

Key terms: system query, isolation, consistent snapshot, ACID, statement-level isolation, transaction-level isolation, SQL SELECT, serializable isolation, isolation levels, throughput

12.1.4 Implementing findOrder() in a monolith is straightforward

Explains why a monolith can retrieve order details and provide a consistent result for findOrder() using its single database and centralized transaction manager.

Key terms: findOrder(), SELECT statements, joins, domain module boundaries, transaction, data consistency, transactional isolation, transaction manager, @Transactional

12.1.5 Challenges implementing findOrder() in a microservice architecture

This section explains why findOrder() is harder to implement across microservices: its data is scattered across services, which cannot use cross-service joins or a single ACID transaction.

Key terms: distributed system query, findOrder(), Order Service, Kitchen Service, Delivery Service, Accounting Service, joins across services, APIs, loose design-time coupling, API-based collaboration

12.1.6 Overview of the service collaboration patterns for queries

Introduces API composition and CQRS as two ways to implement system queries, and summarizes their consistency tradeoffs.

Key terms: API composition, CQRS, services that own the data, replica database, change events, eventually consistent, ACID transactions, decomposition into services, eventual consistency, service boundaries

12.2 Using the API composition pattern

12.2.1 Overview of the API Composition pattern

This section explains how API Composition answers a system query by combining data from provider services, and why the approach is not feasible for every query.

Key terms: API composer, API composition service, provider services, service queries, synchronous request/response, service query, in-memory join, API Composition

12.2.2 Implementing the findOrder() system query using the API composition pattern

Shows why findOrder() suits API composition and how a composer joins data retrieved from four provider services.

Key terms: findOrder(), API composition pattern, orderId, equijoin query, Find Order Composer, GET /orders/{orderId}, Provider service, primary key, foreign key

12.2.3 Benefits

This section explains two benefits of API composition: it is often straightforward to implement, and clients can read their own writes.

Key terms: API composer logic, synchronous request/response, read their own writes, eventually consistent replicas, primary data

12.2.4 Drawbacks

This section explains the performance, availability, consistency, and query-fit drawbacks of API composition.

Key terms: API composition pattern, overhead, TLS-based communication, API composer, provider services, availability, Circuit Breaker pattern, Fallback pattern, transactional data consistency, ACID database transaction

12.3 API composition design issues

This section introduces the design issues to be addressed when implementing API composition.

12.3.1 The location of the API composer

This section explains where an API composer can be located and how the query’s clients and aggregation needs guide that choice.

Key terms: service client, API composer, API gateway, external API, Backend-for-frontend (BFF), API composition, composition service, system query, aggregation logic

12.3.2 Designing the provider queries and composition logic

This section explains how to plan provider queries and composition logic, handle inconsistent results, and coordinate with teams that own provider services.

Key terms: provider queries, composition logic, query planner, remote calls, inconsistent results, inner join, outer join, partial data, service queries, collaborate

12.3.3 Resilient and performant API Composition

This section explains how API composers can limit provider failures and query latency through resiliency patterns, fallbacks, and concurrent calls.

Key terms: runtime coupling, synchronous communication, provider services, latency, provider proxy, Circuit breaker, Time limiter, Bulkhead, fail-fast, Fallback pattern

12.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 11: The design of the FTGO 'Create Order saga' Chapter 13: Using the CQRS pattern to implement system queries →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.