What is API Composition
Combining data from multiple services
API Composition
API Composition is a microservices architecture pattern for aggregating data from multiple services into a single client response.
How It Works
| Step | Action | |------|--------| | 1. Request | Client calls API Gateway | | 2. Decomposition | Gateway identifies needed services | | 3. Parallel calls | Requests to microservices | | 4. Aggregation | Combining results | | 5. Response | Return composite response |
Implementation Options
- API Gateway — centralized aggregation
- BFF (Backend for Frontend) — separate layer for each client
- GraphQL — flexible selection via resolvers
- Orchestrator — coordinator service
When to Use
- Composite pages (dashboards, profiles)
- Reports from multiple sources
- Mobile apps (minimize requests)
- Public APIs (hide internal structure)
Pros and Cons
| Pros | Cons | |------|------| | Fewer client requests | Implementation complexity | | Logic encapsulation | Potential latency | | Response flexibility | Transaction management |