Course contentsShow
← System Design
Lesson 887 of 1,91923. API Gateway PatternFree lesson

API Composition and Aggregation

Combining multiple backend service calls into a single gateway response to reduce client round trips.

API Composition and Aggregation

You'll learn how an API Gateway can combine multiple backend service responses into a single unified response, dramatically reducing the number of network round trips a client needs to make.

The Core Problem

In a microservices architecture, a single user action (like loading a product page) might require data from multiple services: product details, inventory status, user reviews, and recommendations. Without aggregation, the client must make four separate HTTP requests, wait for each response, and assemble the final view—introducing latency and complexity.

How Aggregation Works

The API Gateway acts as an orchestrator. When a client requests /api/product/123, the gateway:

  1. Receives the single request
  2. Makes parallel calls to Product Service, Inventory Service, Review Service, and Recommendation Service
  3. Waits for all responses (or handles partial failures gracefully)
  4. Combines the data into one consolidated JSON response
  5. Returns it to the client

Think of it like ordering a combo meal: instead of visiting the burger counter, fries station, and drink fountain separately, you order once and the staff assembles everything behind the scenes.

Key Benefits

  • Reduced Latency: Parallel backend calls instead of sequential client requests
  • Simpler Clients: Mobile apps and web frontends don't need complex orchestration logic
  • Bandwidth Savings: Fewer HTTP handshakes and header overhead
  • Backend Independence: Services can change without forcing client updates

Trade-offs

The gateway becomes responsible for orchestration logic—knowing which services to call and how to merge responses. This adds gateway complexity but removes it from every client.

Key Takeaway: API composition transforms multiple service calls into a single client request, shifting orchestration complexity from many clients to one intelligent gateway layer.