Scatter-Gather Aggregator - Middle¶
Choose an explicit completion policy: all responses, first k, or best effort until a deadline.
flowchart TD
Start --> Fan[Fan out under one deadline]
Fan --> Gather[Collect replies]
Gather --> Policy{Enough replies?}
Policy -->|yes| Cancel[Cancel remaining calls]
Policy -->|no| Wait[Wait until deadline]
For a federated warehouse catalog search, attach shard identity to every result, deduplicate by object ID, and use a bounded semaphore. A top-k merge keeps one small heap instead of concatenating every result. Propagate cancellation after the policy is satisfied.
Test yourself¶
- When is
k-of-npreferable toall-of-n? - How does a heap bound top-k memory?
- Why cancel unfinished branches?
Continue to senior.md.