Implementing Request Aggregation

1. Configuring Multi-Backend Requests

Client → Gateway → ┬→ /users/42      (user-svc)
                   ├→ /orders?u=42   (order-svc)
                   └→ /prefs/42      (prefs-svc)
        Aggregate → Single JSON response
      

2. Using Parallel Request Execution

Example: Parallel fetch (Java)

CompletableFuture<User>    u = async(() -> userClient.get(id));
CompletableFuture<Orders>  o = async(() -> orderClient.byUser(id));
CompletableFuture<Prefs>   p = async(() -> prefsClient.get(id));

CompletableFuture.allOf(u, o, p)
    .orTimeout(2, TimeUnit.SECONDS)
    .join();

return new Profile(u.join(), o.join(), p.join());
PropertyValue
Latencymax(call_i), not sum
Failure modeAll-or-partial
CancellationCancel in-flight on timeout

3. Implementing Sequential Aggregation

WhenReason
Result of A feeds BDependency
Auth → resourceNeed user from token first
ID resolution → detailsTwo-phase fetch

4. Setting Aggregation Timeout

StrategyDetail
Overall budget2s total wall-clock
Per-call deadlineDecremented from budget
Hedged requestsSend duplicate after p99
Soft timeoutReturn partial after T

5. Implementing Response Merging

PatternExample
Embed{user: {...}, orders: [...]}
Join by keyMerge on shared ID
Hypermedia _embeddedHAL/JSON:API
Side-by-sideParallel arrays

6. Configuring Partial Failure Handling

Example: Partial result with errors[]

{
  "data": {
    "user": { "id": 42, "name": "Ana" },
    "orders": null
  },
  "errors": [
    { "source": "order-svc", "code": "timeout", "message": "504 after 2s" }
  ],
  "_meta": { "partial": true }
}

7. Using GraphQL-Style Aggregation

FeatureBenefit
Single round tripClient requests exact fields
DataLoaderBatches N+1 calls
Schema stitchingMerge multiple backends
FederationIndependent subgraphs

8. Implementing Batch Requests

Example: Batch endpoint

POST /v1/_batch
[
  { "method": "GET", "path": "/users/1" },
  { "method": "GET", "path": "/users/2" },
  { "method": "POST", "path": "/audit", "body": {"event":"viewed"} }
]

[
  { "status": 200, "body": {...} },
  { "status": 404, "body": {"error":"not_found"} },
  { "status": 201, "body": {"id":"a1"} }
]

9. Configuring Response Ordering

OrderUse
Input orderMatch request array
By dependencyResolve dependencies first
By priorityCritical first
StreamedEmit as ready (NDJSON/SSE)

10. Using Conditional Aggregation

TriggerEffect
Field requestedSkip backend if not asked
Permission scopeSkip PII calls if no scope
Feature flagInclude only if enabled
Cache hitSkip upstream entirely