Stackbook Logo
messagingestablished · medium operational burden

Scatter-Gather

Also known as: fan-out-fan-in, scatter-gather-aggregator

Intent

Send a request to several recipients in parallel and combine their replies into one result.

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.

Forces

  • •Sources are independent and can run in parallel
  • •Latency should track the slowest needed reply, not the sum
  • •Some responders will fail or time out
  • •Results must be combined or ranked consistently

Solution

Overview

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.

How it works

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.

Pitfalls

  • Waiting for every responder. Always set a deadline and decide what partial means to the caller.
  • Load amplification. A fan-out of 50 turns one request into 50; apply concurrency limits and circuit breakers per recipient.
  • Tail latency. The more responders, the more likely one is slow; use hedging or drop stragglers.
  • Orphaned work. Cancel outstanding calls once the answer is complete.
  • Inconsistent ranking when sources use different scoring scales; normalise before merging.

Key takeaways

  • Parallel fan-out, correlated fan-in, bounded by a deadline.
  • Choose completion policy deliberately: all, quorum or first.
  • Protect recipients from amplified load.
  • Make partial results explicit to callers.

✓ When to Use

  • •Querying sharded indexes or partitions
  • •Comparing quotes from multiple providers
  • •Redundant calls to cut tail latency

✗ When Not to Use

  • •Dependent steps where each needs the prior result
  • •Expensive requests where fan-out cost outweighs value
  • •Strict transactional requirements across recipients

Pros

  • +Latency bounded by the deadline rather than the sum
  • +Tolerates failed or slow responders
  • +Natural for sharded or multi-vendor queries

Cons

  • −Load multiplies by fan-out factor
  • −Partial results complicate semantics
  • −Aggregation logic can be intricate

Cost Profile

Infrastructure

Medium - extra downstream load

Operational

Medium - timeout and partial-result tuning

Cognitive

Medium - concurrency and correlation

Failure Modes

  • 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

Real-World Examples

Alternatives

    Related Patterns

    • circuit-breaker

    Competency Domains

    distribution communicationreliability ops