← Lessons

quiz vs the machine

Gold1380

System Design

The API Composition Pattern

Build one response by querying several services and joining results.

4 min read · core · beat Gold to climb

The problem

With a database per service, no single query can join across services. A page that shows an order plus its customer plus its shipping status needs data from three owners.

The composer

The API composition pattern uses a composer, often an API gateway or a dedicated service, to:

  • Call each owning service for its piece.
  • Join the results in memory.
  • Return one combined response.

Trade offs

  • It is simple and needs no shared database.
  • But it does in memory joins, which are costly for large sets.
  • It is chatty, since one request fans out to many calls.

When to avoid

For complex reporting or huge joins, prefer CQRS with a precomputed read model instead of composing on every request. Composition shines for small, bounded lookups.

Key idea

API composition gathers pieces from several services and joins them in memory, ideal for small lookups but weak for large joins.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is API composition needed in microservices?

2. When should you avoid API composition?