Where the Merge Happens: Client, Gateway, BFF, GraphQL, and Edge Composition Compared
When an interface needs data from four backend services, comparing client fan-out, API gateways, BFFs, and GraphQL resolvers.
On this page
Consider a modern e-commerce mobile product screen. To render a single view, the client application requires data from four completely independent microservices:
- Catalog Service: Product title, description, and high-res image URLs.
- Pricing & Promotions Service: Current discount, currency, and coupon eligibility.
- Inventory Service: Stock availability across regional fulfillment centers.
- Reviews Service: Star rating, review count, and top customer testimonials.
In a microservice architecture, each service owns only its private domain database. No single service possesses the complete picture.
Something in your system must issue requests to all four services, wait for the responses, handle partial network failures, and merge the data into the exact JSON contract required by the user interface.
This merge step is API Composition.
Where you place this composition layer is one of the most critical architectural decisions in distributed systems. It determines your mobile latency, partial outage resiliency, caching efficiency, and team deployment velocity.
+--------------------------------------------------------------------------+
| THE FIVE API COMPOSITION TOPOLOGIES |
| |
| 1. Client-Side Composition : Mobile app calls all 4 services directly |
| 2. Centralized Gateway : API Gateway (Kong/Envoy) fans out in DC |
| 3. Backend for Frontend : Dedicated NodeJS/Go service per client type|
| 4. GraphQL Federation : Declarative schema with distributed resolve|
| 5. CDN Edge Worker : Cloudflare / Vercel Edge merges at CDN PoP |
+--------------------------------------------------------------------------+
Topology 1: Client-Side Composition (The Anti-Pattern)
The simplest initial approach is to make the mobile client or web browser responsible for composition:
Mobile Phone (Cellular Network: 120ms RTT)
|
+---> [GET /catalog/p102] (120ms)
+---> [GET /pricing/p102] (120ms)
+---> [GET /inventory/p102] (120ms)
+---> [GET /reviews/p102] (120ms)
On a fast developer laptop connected to fiber internet, this looks fine. On a cellular connection with 120 ms round-trip latency, it is disastrous:
- Radio Resource Exhaustion: The phone’s cellular modem must keep its high-power state active for multiple concurrent round trips, draining battery.
- Cascading Latency: If the Reviews call depends on an author ID returned by Catalog, the requests become sequential, pushing render latency over 600 ms.
- Over-Fetching: The phone downloads megabytes of internal database fields (audit timestamps, internal IDs) that the UI never displays.
The Latency Paradox: Why Adding a Server Hop Makes Apps Faster
Engineers often assume that adding an intermediate composition server adds latency because it introduces an extra hop.
In reality, adding a composition hop drastically reduces total user latency:
Client-Side Fan-out:
Cellular Network (100ms) x 4 requests = 400ms sequential latency (or high contention)
Server-Side Composition:
Client -> Edge Hop (100ms) -> Data Center Internal Network (0.5ms hop x 4) -> Edge -> Client
Total User Latency = 100ms + 100ms + 5ms = 205ms (A 50% speedup!)
One high-latency mobile round trip is traded for internal data center connections operating over 100 Gbps fiber at sub-millisecond speeds.
Topology 2: Centralized API Gateway Aggregation
A common evolution is using a centralized API Gateway (such as Kong, Apisix, or Envoy) to aggregate responses:
- The mobile app calls
GET /api/v1/product-summary/p102. - The gateway uses a plugin or Lua script to fan out to the four upstream microservices concurrently and merges the payloads.
The Failure Mode: The API Gateway becomes an organizational bottleneck. When the mobile iOS team needs a new field, they must submit a ticket to the centralized infrastructure or gateway team. Over time, the gateway accumulates tangled business logic, turning into a brittle distributed monolith.
Topology 3: Backend for Frontend (BFF)
Pioneered by SoundCloud and documented by Sam Newman, the Backend for Frontend (BFF) pattern assigns ownership of the composition service directly to the frontend engineering team:
[Mobile iOS App] ---> [iOS BFF (Node.js / Go)] ---> Internal Microservices
[Web Desktop App] ---> [Web BFF (Next.js / SSR)] ---> Internal Microservices
[Smart Watch App] ---> [Watch BFF (Lightweight)] ---> Internal Microservices
- Tailored Contracts: The iOS BFF emits a compact, pre-formatted JSON payload optimized for small mobile screens. The Web BFF returns richer metadata and desktop sidebar data.
- Autonomous Release Cycles: The mobile team deploys updates to their own BFF daily without coordinating with backend catalog or billing teams.
- Tradeoff: Code duplication across multiple BFF services and increased infrastructure operational overhead.
Topology 4: GraphQL Federation
Rather than writing manual aggregation code in a BFF, GraphQL Federation (Apollo Federation) uses a declarative approach:
- Each microservice implements a GraphQL subgraph and declares its entity types.
- The Catalog service declares type
Product { id: ID!, title: String! }. - The Reviews service extends the entity:
extend type Product { reviews: [Review!]! }. - A central Federation Router analyzes the incoming client query, generates an execution query plan, queries the underlying subgraphs in parallel, and stitches the response together automatically.
Tradeoffs: GraphQL eliminates over-fetching and manual BFF boilerplate, but introduces significant query complexity, hard-to-debug N+1 database queries, and caching hurdles (HTTP POST queries break standard CDN edge caching).
Topology 5: CDN Edge Worker Composition
The most modern pattern executes composition at the Content Delivery Network (CDN) Edge (Cloudflare Workers, Fastly Compute, Vercel Edge):
- The composition code runs on edge servers located physically within 15 milliseconds of the user’s device.
- Edge workers use
Promise.all()to fan out requests to origin data centers. - Fast-changing data (pricing, inventory) is fetched live, while static data (catalog titles, image URLs) is cached directly in local edge memory.
- If one service fails, the edge worker returns a cached or degraded response in milliseconds.
Resilience: Handling Partial Failures
The ultimate test of an API composition layer is how it responds when one of the four downstream services crashes:
Catalog: 200 OK (Product Title: "Ergonomic Chair")
Pricing: 200 OK (Price: "$299")
Inventory: 200 OK (In Stock: 5)
Reviews: 504 Gateway Timeout! (Service Outage)
Never fail the entire screen because a secondary service is down.
The composition layer must implement Graceful Degradation:
- Wrap every upstream call in a strict timeout (e.g., 200 ms).
- If the Reviews service times out or returns a 500 error, catch the exception and populate the review field with a safe fallback:
{ rating: null, review_count: 0, status: "temporarily_unavailable" }. - The user can still view the product, see the price, and purchase the chair. An outage in an auxiliary service never interrupts the primary conversion funnel.
Architectural Decision Matrix
| Dimension | Client Fan-out | Central Gateway | Backend for Frontend | GraphQL Federation | Edge Worker |
|---|---|---|---|---|---|
| Mobile Latency | Terrible (Multiple RTTs) | Very Fast | Very Fast | Fast | Instant (PoP proximity) |
| Over-Fetching | High | Low | Zero (Custom contract) | Zero (Client-selected) | Low |
| Team Ownership | Frontend | Central Platform | Frontend Teams | Federated Domain Teams | Frontend / Edge |
| Partial Outage Risk | High (Client crashes) | Medium | Handled via fallbacks | Handled via nullability | Handled via edge cache |
| Caching Support | High | Standard HTTP | Standard HTTP | Complex (POST queries) | Superior (Edge RAM) |
API composition is fundamentally about deciding who owns the boundary between internal domain complexity and the external user experience.
/* Comments */
Comments are offline right now — we reconnect automatically, nothing is lost.