Implementing Service Aggregation Patterns

1. API Composition Pattern

AspectDetail
DefinitionComposer service queries multiple services and joins results in memory
Use CaseCross-service queries when CQRS read model not justified
ProsSimple; no extra storage
ConsLatency = slowest call; expensive for large joins

2. Aggregator Service Pattern

PropertyDetail
RoleDedicated service that orchestrates calls and merges responses
OwnsAggregation logic and DTOs
AvoidsEach client doing its own composition

3. Composite Service Pattern

AspectDetail
DefinitionHigher-level service composed of lower-level services
Layered ViewEdge / Composite / Atomic services
WatchoutRisk of cascading failures down the layers

4. Response Aggregation Pattern

StrategyDetail
All-or-NothingFail entire response if any sub-call fails
Partial ResponseReturn what succeeded; mark failures
Best-EffortReturn defaults / cached for failures

Example: Partial Response

{
  "order": { "id": "123", "status": "PAID" },
  "shipping": { "error": "service_unavailable", "trackingId": null },
  "recommendations": [{ "productId": "p9" }]
}

5. Parallel Service Call Pattern

AspectDetail
WhenCalls are independent
Latency= max(call1, call2, ..., callN)
ImplementationCompletableFuture (Java), Promise.all (JS), goroutines (Go)
ToolingAdd per-call timeout; combine with circuit breaker

6. Sequential Service Call Pattern

AspectDetail
WhenEach call depends on previous result
Latency= sum of all calls (worst pattern for chains)
MitigationAvoid chains >3; restructure or pre-fetch
Warning: Long synchronous chains compound latency and failure probability. P(success) = ∏ p(each).

7. Scatter-Gather Pattern

StepAction
ScatterSend same request to N services in parallel
GatherCollect responses
CombineAggregate (sum, best-of, all)
Use CaseSearch across shards, multi-vendor price quotes

8. Partial Response Pattern

MechanismDetail
Field SelectionClient requests subset (?fields=id,name or GraphQL)
Sparse FieldsetsJSON:API fields[orders]=id,total
BenefitSmaller payloads; faster mobile

9. Data Joining Pattern

ApproachDetail
In-Memory JoinAggregator joins after fetching
Materialized ViewPre-joined read model maintained via events
Stream JoinKafka Streams / Flink joins event streams
Anti-PatternSQL JOIN across service DBs

10. Content Enricher Pattern

AspectDetail
DefinitionAugment message with data from external source before forwarding
ExamplesAdd customer name to OrderPlaced event from customer service
WhereStream processor, message gateway, ESB-style mediator