liveBook · Manning

Service collaboration pattern

As explained in Microservices Patterns, Second Edition

A recurring architectural solution for coordinating interactions and distributed operations among services.

Service collaboration patterns coordinate operations that span services in a microservice architecture. A distributed operation may combine patterns; service interactions use interprocess communication such as REST or asynchronous messaging. section 7.6.2 section 8.0

Choose a pattern by the responsibility it fulfills:

  • Saga implements a distributed command as local transactions across participating services. section 7.6.2
  • Command-side replica keeps read-only data from another service for efficient querying by a command API. section 7.6.2
  • API Composition queries multiple data-owning services and aggregates their results; CQRS uses a combined read-only replica for distributed queries. section 7.6.2

Finding an order

A findOrder() query may need information owned by several services. It must use their APIs rather than database joins or direct access to their persistence, and its parts run in independent local transactions rather than one ACID transaction. section 12.1 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

The figure summarizes why distributed queries cannot rely on joins or distributed transactions when data is scattered across services. section 12.1.5

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines four patterns by responsibility, while deferring their detailed implementation to separate command and query treatments.
Examples
Uses findOrder() to illustrate a query requiring data from multiple services and independent local transactions.
What it assumes
Assumes a microservice architecture with service-owned data and cross-process interactions; foundational concepts are not taught from zero.
What you can do after
Evaluate collaboration options by whether an operation is a distributed command or query and whether query data is aggregated or replicated.
How it connects
Connects Saga and command-side replicas with distributed commands, and API Composition and CQRS with distributed queries.

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.