Scatter-Gather
Fan-out/fan-in — ask 5 partners in parallel and pick the best response.
Problem
For a Request For Quote (REQOTE), one wants to query 5 suppliers in parallel and pick the best offer. How to parallelise without blocking?
Forces
- Sequential = N × individual latency (intolerable for N=10).
- The client wants a fast answer even if some recipients are slow.
- Different strategies: all (wait for all), first N, first to respond, best per criterion.
- EDI: some partners may never reply — a timeout is needed.
Solution
The coordinator (Scatter-Gather) sends the message in parallel to N recipients (via Recipient List or Publish-Subscribe), starts a timer, collects responses arriving out of order, and applies an aggregation strategy: "all", "first N", "best per criterion". Returns the aggregated response after timeout or completion.
EDI implementation
In EDI, typical case: REQOTE to 5 suppliers, wait 30 seconds, take the first 3 QUOTES received and present to the buyer. Camel implementation: `multicast().parallelProcessing().aggregationStrategy(bestQuote)`. For PEPPOL multi-AP discovery, query multiple SMPs in parallel and take the first consistent response.
Anti-patterns
- No timeout — a silent recipient blocks everything.
- Strict wait-for-all when some recipients are chronically slow.
- Hidden partial response — the end user thinks they got 5 quotes when they got 2.
Related patterns
- Recipient List — static fan-out recipients.
- Publish-Subscribe — broadcast alternative.
- Aggregator — gather component.
Sources
- Hohpe G., Woolf B. — EIP, Scatter-Gather (p. 297). www.enterpriseintegrationpatterns.com/patterns/messaging/BroadcastAggregate.html