Prompt
How do I aggregate APIs from multiple microservices?
Latest observation
A common way to aggregate APIs from multiple microservices is to put an API Gateway or Backend-for-Frontend (BFF) in front of them.
Typical approaches
1) API Gateway
Use a gateway as the single entry point for clients.
- Routes requests to the right microservice
- Can handle auth, rate limiting, logging, caching
- Sometimes can combine responses from multiple services
Good for: centralizing cross-cutting concerns and simplifying client access.
2) BFF (Backend for Frontend)
Create a separate aggregation layer per client type, such as:
- Web app BFF
- Mobile app BFF
This layer calls multiple microservices and returns a client-specific response.
Good for: tailoring APIs to UI needs and avoiding overfetching.
3) Composite / Aggregator Service
A dedicated service that:
- Calls several microservices
- Merges/normalizes the data
- Returns one response to the client
This is often implemented as part of a BFF.
Good for: building a single endpoint from multiple internal services.
Design patterns to use
Orchestration
The aggregator controls the flow:
- Call service A
- Call service B
- Merge results
- Return response
Parallel calls
If services are independent, call them concurrently to reduce latency.
Resilience
Use:
- timeouts
- retries with backoff
- circuit breakers
- fallbacks / partial responses
Example
Suppose you need a “user dashboard” response:
UserService→ profileOrderService→ recent ordersNotificationService→ unread notifications
Aggregator endpoint:
GET /dashboard
Returns:
{
"profile": {...},
"recentOrders": [...],
"unreadNotifications": 3
}
Implementation options
Depending on your stack, aggregation can be done with:
- Node.js / Express
- Spring Boot
- .NET
- GraphQL gateway
- Apollo Federation
- Kong / Apigee / AWS API Gateway for routing, plus custom aggregation logic elsewhere
Key cautions
- Avoid making the gateway too smart; it can become a monolith
- Watch for chatty calls and N+1 request patterns
- Keep service contracts stable
- Add caching where appropriate
- Use observability: tracing, logs, metrics
If you want, I can also show:
- a Node.js example
- a Spring Boot example
- a GraphQL federation approach
- an architecture diagram