Problem
A query needs answers from multiple independent sources, such as shards, vendors or price providers. Asking them sequentially is slow, and some sources may be slow or unavailable.
Also known as: fan-out-fan-in, scatter-gather-aggregator
Send a request to several recipients in parallel and combine their replies into one result.
A query needs answers from multiple independent sources, such as shards, vendors or price providers. Asking them sequentially is slow, and some sources may be slow or unavailable.
Scatter-gather is a messaging and orchestration pattern in which one request fans out to many recipients and one aggregator fans the replies back in. It is the backbone of distributed search, price comparison and multi-shard queries.
The coordinator assigns a correlation id, sends the request to every recipient in parallel and waits under a deadline.
request(id=77) --> scatter --> shard-1 --\
\--> shard-2 ---+--> gather(id=77) --> merge/rank --> response
\-> shard-3 --/
completion: all replies OR quorum OR deadline 200 ms
Completion policy is the key design choice. Search often waits for the deadline and returns what arrived, flagging partial results. Price comparison may wait for all vendors up to a timeout. Latency hedging sends the same request to replicas and takes the first answer, cancelling the rest. The gatherer discards late replies by correlation id.
Medium - extra downstream load
Medium - timeout and partial-result tuning
Medium - concurrency and correlation
One slow shard drags every query to the timeout
Late replies arrive after aggregation and leak resources
Fan-out overload turns a traffic spike into a downstream outage