Build one answer by calling several services and combining the results in one place.
API composition means that when one answer needs data from several services, one piece of code (the composer) calls them all and joins the results in memory.
Think about a product page in a shop. It shows the product details, the price, the reviews and a list of recommended items. In a microservices system, each of these four things lives in its own service, with its own database. There is no single table to JOIN.
So someone has to ask each service and put the answers together. That is the API composition pattern. The composer receives one request from the client, sends several requests to the services behind it, waits for the answers, builds one combined response, and sends it back.
The composer does no business work of its own. It is a coordinator: it knows which services to call, in which order, what to do when one is slow or down, and how to merge the pieces into the shape the client wants.
| Composer | What it is | Good for |
|---|---|---|
| API gateway | The edge door of the system also combines a few calls | Simple joins that every client needs |
| Backend for frontend | One backend per client type, shaped for its screens | Mobile and web needing different data |
| Aggregator service | A normal service whose job is to combine others | Reusable composition, shared by several clients |
| GraphQL layer | Resolvers fetch each field from the right service | Clients that choose their own fields |
| Style | How it works | Total time | Use when |
|---|---|---|---|
| Parallel | Send all calls at once, then wait for all | About the slowest call | The calls do not need each other's answers |
| Sequential | Call one, use its answer for the next | The sum of the calls | Call B needs data from call A |
| Mixed | Some in parallel, some after a first step | In between | Most real pages: fetch the product first, then price and stock for it |
A simplified model with made-up numbers (illustrative): a service that is down is noticed after 300 ms, optional parts get 120 ms in partial mode, and the composer itself costs 5 ms. In the fail-all mode the composer waits for every reply before it decides. Availability is the exact product of the services that must work: availability to the power of 4, assuming independent failures, over a 30-day month. Real systems also share failures (the same network, the same data centre).
| Term | Meaning in easy words |
|---|---|
| Composer | The code that calls several services and combines their answers (also called an aggregator) |
| Fan-out | Sending one request on to many services |
| Join in memory | Merging results in the application instead of in a database |
| Parallel calls | Calls started at the same time, so they overlap |
| Sequential calls | Calls made one after another because each needs the last answer |
| Tail latency | The slowest few calls, which decide how long the whole page takes |
| Partial response | An answer with some parts missing, because an optional service failed |
| Fallback | A safe substitute (cached data, a default) when a call fails |
| Deadline | The total time a request may take, shared by all its calls |
| Read model | A separate, ready-made view of data, built for fast reading |
| Aggregator | A service whose main job is to compose other services |
| Choice | We gain | We lose |
|---|---|---|
| Parallel calls | Time of the slowest call only | More load at once, and more code to handle many results |
| Sequential calls | Simple logic, can use earlier answers | Time adds up with every call |
| Fail the whole page | Simple, the data is always complete | One small service can take the page down |
| Partial page + fallback | A page that works most of the time | Users may see missing parts, and you must design those states |
| Cache composed answers | Fast and cheap | Data may be stale for a while |
| Read model instead of composition | Fast queries, filters and sorting across services | More moving parts and eventual consistency |