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.
The figure summarizes why distributed queries cannot rely on joins or distributed transactions when data is scattered across services. section 12.1.5
