What is the API composition pattern?

Answer

The API composition pattern is used to query data that is spread across multiple microservices. An API composer (typically the API gateway or a dedicated aggregator service) makes parallel calls to multiple services and merges their results into a single response for the client. For example, displaying an order detail page might require fetching order data from the order service, customer info from the customer service, and shipping status from the shipping service — the composer retrieves all three and combines them. The limitation is that API composition only works well for simple aggregations; complex queries (like a filtered, sorted, paginated list spanning multiple services) require a separate CQRS read model or search index instead.