We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Api Design Protocols
Free preview: the first 2 parts of this 9-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Api Design Protocols
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
A user profile page shows name and avatar (User Service), recent orders (Order Service), loyalty points (Gamification Service), subscription status (Billing Service), and recommendations (ML Service). In a monolith, one database query joins these tables. In , the data lives in five different services with five different databases.
Who assembles the profile? The frontend could make five API calls, but on a mobile connection each call takes 200 to 400ms for the round trip alone. Five sequential calls: 1 to 2 seconds of pure network time before the page renders. Even in parallel, the browser is making five TLS handshakes, parsing five JSON responses, and handling five potential failure scenarios in the client code.
API composition is the pattern of aggregating data from multiple backend services into a single API response. A server-side compositor (an , a BFF, or a dedicated aggregation service) makes the downstream calls in parallel, merges the results, and returns one response to the client. The client makes one call and gets everything it needs.
Netflix's Zuul gateway composes data from over 100 microservices into single responses for the Netflix app. Spotify's API gateway aggregates from 800+ microservices. Uber's query platform composes ride, payment, and driver data for every screen. This is one of the most practical patterns in microservice architecture. Every application with a dashboard, detail page, or complex view needs some form of API composition.
1. composition. The gateway routes requests and composes responses from multiple services. Kong, AWS API Gateway, and Netflix Zuul all support this. Simple for 2 to 3 services, but composition logic in the gateway becomes unmaintainable at 10+ services.
2. Dedicated composition service. A thin service whose only job is fan-out, wait, merge, and return. No business logic, no database. Owned by the team responsible for the composed endpoint (like the "Profile Page Service"). This scales better than gateway composition because each endpoint has its own service with its own deploy cycle.
3. Backend for Frontend (BFF). A dedicated backend per client type that composes exactly what that client needs. The web BFF returns rich data, the mobile BFF returns compact data. (Covered in the next lesson.)
4. resolver composition. Each field resolves independently from its own data source. The GraphQL server naturally composes data from multiple services based on the client's query.
Parallel calls are almost always correct. If each service takes 100ms and you call them sequentially, the composed response takes 500ms (5 * 100ms). In parallel: ~100ms (limited by the slowest). That is a 5x improvement.
| Decision | Option A | Option B | Recommendation |
|---|---|---|---|
| Call pattern | Sequential (A then B then C) | Parallel (A + B + C) | Parallel unless B depends on A's result |
| Failure handling | Fail entire response | Return partial data + error flags | Partial for dashboards, fail-fast for transactions |
| Timeout strategy | Wait for slowest | Return after deadline, skip stragglers | Hard deadline (500ms), skip slow services |
| Cache composed response | Cache individual service responses | Cache individual (more reusable, finer invalidation) |
It is easy and good
“It is really nice and good Please join the course”