Pattern
Scatter–gather
Problem
You need to answer a query that requires data from multiple shards/services, and you need the aggregate result.
Context
Search across N sharded indexes; get user's items from 5 different services; run analytics across shards.
Solution
Fan out the query in parallel to all N sources. Wait for responses (with timeouts). Aggregate the results into a single response.
Trade-offs
- Latency = max(slowest response) — tail latency dominates
- Bandwidth cost: 1 query becomes N queries
- Partial results may be returned if some sources time out
Failure modes
- One slow shard makes every query slow — mitigate with per-shard timeout + partial results
- One shard returns bad data — aggregator can't validate
- Fanout multiplied by N shards → massive load on all shards
When to use
- Sharded search (find X across all shards)
- Federated queries across services
- Multi-region aggregation
When NOT to use
- You can pre-aggregate the data (denormalize)
- Query hits only one shard by key — no scatter needed