Parallel fan-out and merge: split a task, run the parts together, combine the results

Fan-out splits one task into independent parts, runs them at the same time, and merges what comes back. Use it when the parts do not depend on each other and waiting for them one by one is too slow.

Parallel fan-out in 60 seconds

  • What: split a task into independent parts, run each part at once with its own timeout, then merge the results.
  • Who decides the path: your code. The split is fixed or computed, and the merge rule is explicit.
  • Best for: research across several sources, checking one item against several rules, and any job where sequential waiting is the main cost.
  • Weak spots: parts that secretly depend on each other, partial failures, rate limits, and merge steps that hide gaps.
  • Origin: LLMCompiler (Kim et al., 2023) plans function calls as a dependency graph and runs independent calls in parallel.

Where this type fits

Fan-out is in the group of patterns where your code decides the path, alongside the pipeline, the router, and the state graph. A pipeline runs stages in a line. Fan-out runs branches side by side. Read the orchestration hub to compare them.

The problem it solves

Suppose a task needs three pieces of research, and each model call takes about twenty seconds. Done in order, the user waits a minute. Yet none of the pieces needs the others. The time is spent waiting, not thinking. A single agent that handles the pieces one after another also tends to fill its context with the first piece before it starts the third, which can bias the later work.

Fan-out removes the waiting. The three pieces start together, so the total time is close to the slowest piece, not the sum. Each branch also gets a clean, short context with one job, which often improves quality.

The pattern brings its own risks. Branches can fail or run late. Together they can hit rate limits that one call would not. And the merge step can quietly drop a missing result and still produce a confident summary. Good fan-out design is mostly about handling these three problems.

How it works

  • Split. Break the task into parts that do not need each other's output. The split can be fixed in code or produced by a model, then checked.
  • Dispatch. Start every branch at once. Give each its own prompt, tools, and timeout. Cap the number of branches that run together.
  • Collect. Wait for all branches or until a global deadline. Record each branch as done, failed, or timed out.
  • Merge. Combine the successful results using a clear rule: concatenate, rank, vote, or ask a model to synthesise. Carry forward the list of branches that did not finish.
  • Report gaps. State plainly which parts are missing, so the reader does not mistake a partial result for a complete one.
Three independent branches run together, each with its own timeout, and the merge step keeps what worked and flags what did not.

The branches in the diagram share nothing while they run. That independence is what makes parallel work safe. If branch two needed the answer from branch one, they would have to run in order, and the pattern would be wrong for that task.

The merge step is where the value is combined, and where mistakes hide. A plain merge, such as joining sections under headings, is easy to check. A model-written synthesis reads better but can smooth over disagreements, so give it the gap list and ask it to name conflicts.

A worked example

Acme's sales team asks for a vendor review of "Northwind Analytics" before a renewal call. The system fans out three branches with a 30 second timeout each.

  • Pricing branch: reads the contract and price list. Returns in 12 seconds: "Annual plan 48,000, 8 percent uplift clause on renewal."
  • Security branch: reads the security questionnaire. Returns in 21 seconds: "Encryption at rest and in transit confirmed. Penetration test report is two years old."
  • Support branch: queries the ticket system, which is slow. It times out at 30 seconds with no result.
  • Merge: keeps the two results, marks support as timed_out, and writes a summary with a section titled "Not reviewed: support history".
  • Output: a one-page brief. The sales lead sees the gap, and can retry the support branch alone.

Total time was 30 seconds, set by the deadline. Done in order, the same work would have taken at least 63 seconds, and the timed-out part would have blocked everything after it.

Building it

Fan-out with per-branch timeouts and a concurrency cap (illustrative) (python)
import asyncio

MAX_CONCURRENT = 4        # protects rate limits and spend
BRANCH_TIMEOUT_S = 30     # one slow branch must not hold up the rest

async def run_branch(name: str, prompt: str, sem: asyncio.Semaphore):
    async with sem:
        try:
            # Placeholder for a model call with its own tools.
            text = await asyncio.wait_for(
                llm.generate_async(prompt), timeout=BRANCH_TIMEOUT_S
            )
            return {"branch": name, "status": "done", "text": text}
        except asyncio.TimeoutError:
            return {"branch": name, "status": "timed_out", "text": ""}
        except Exception as exc:
            # One failing branch must not cancel the others.
            return {"branch": name, "status": "failed", "text": str(exc)[:200]}

async def fan_out(task: str, parts: dict[str, str]):
    sem = asyncio.Semaphore(MAX_CONCURRENT)
    jobs = [
        run_branch(name, f"{instruction}\n\nTask: {task}", sem)
        for name, instruction in parts.items()
    ]
    results = await asyncio.gather(*jobs)   # exceptions are handled above
    return list(results)

def merge(results):
    ok = [r for r in results if r["status"] == "done"]
    missing = [r["branch"] for r in results if r["status"] != "done"]
    body = "\n\n".join(f"## {r['branch']}\n{r['text']}" for r in ok)
    gaps = ", ".join(missing) if missing else "none"
    return f"{body}\n\nNot reviewed: {gaps}"

# parts = {"pricing": PRICING_PROMPT, "security": SEC_PROMPT, "support": SUP_PROMPT}
# report = merge(asyncio.run(fan_out("Review Northwind Analytics", parts)))

llm.generate_async and the prompt constants are placeholders. The structure to copy is the semaphore, the per-branch timeout, and the rule that every branch returns a status instead of raising.

Design decisions

  • Independence check: only fan out parts with no data dependency. If in doubt, run in order first and measure. Parallelism you add later is easy; hidden dependencies are hard to find.
  • Concurrency cap: set a limit below your provider rate limit and your budget. Four to eight branches is a sensible start. Queue the rest rather than rejecting them.
  • Timeouts: give each branch its own timeout, plus a global deadline. Choose them from the 95th percentile of branch latency, not the average.
  • Partial results: decide in advance whether the task can finish with missing branches. Mark each branch as required or optional, and fail loudly when a required one is missing.
  • Merge rule: prefer a simple, checkable merge. When you use a model to synthesise, pass it the gap list and ask it to name disagreements between branches.
  • Retries: retry only branches that are safe to repeat, with a small limit and backoff. Give side-effecting branches an idempotency key; see idempotency.
  • Cost control: parallel work spends the same tokens faster. Set a total token budget for the whole fan-out, not just per branch.

Measuring it

  • Speed-up: sequential time divided by fan-out time for the same tasks. Compute the sequential time from the sum of branch times.
  • Branch success rate: done branches divided by started branches, per branch type.
  • Timeout rate: timed-out branches divided by started branches. A high rate for one branch suggests its limit or its tool is wrong.
  • Gap rate: the share of final outputs with at least one missing branch. Review these by hand.
  • Merge quality: grade a sample of merged outputs against a rubric, and compare with the best single branch to confirm the merge adds value.
  • Cost per task: total tokens across branches times price, compared with the sequential version.

When to use it, and when not to

SituationUse this type?Why
Research across several independent sourcesYesBranches do not need each other, and waiting in order wastes time.
Checking one document against many rulesYesEach rule check is a small independent job that can run alongside the rest.
Each step needs the previous step's outputNoThat is a pipeline. Parallel branches would have nothing to work from.
Strict rate limits or a tight token budgetWith careParallel calls hit limits sooner. Cap concurrency and budget the total.
Parts where one result changes what to ask nextNoUse a state graph so the path can change after each step.
Tasks where partial answers are unacceptableWith careMark branches as required and fail the task when one is missing.

Trade-offs

DimensionEffectWhat to do about it
QualityFocused branches often improve each part. A careless merge can lose detail or hide conflicts.Use a checkable merge and report gaps and disagreements.
LatencyTotal time drops to about the slowest branch, plus the merge.Set a global deadline so one slow branch cannot set the pace.
CostSame or higher token use, spent sooner. Retries add more.Set a task-level token budget and cap retries.
ComplexityNeeds concurrency control, status tracking, and a merge design.Keep branch results in one small status shape and test the merge alone.
Failure modesPartial failure, rate-limit spikes, and merges that present gaps as completeness.Return a status for every branch and show missing parts to the reader.

A pipeline is the sequential cousin: each stage waits for the one before it. Use a pipeline when later steps need earlier results, and fan-out when they do not. Many systems use both, with a fan-out inside one pipeline stage.

A supervisor with workers also uses several workers, but a model decides the split and may change it as results arrive. Fan-out fixes the split up front, which is simpler to test and cheaper to run. A router picks one path, whereas fan-out starts several at once.

What this means for your role

Common mistakes

Further reading

Fan-out is a simple idea with three details that matter: independence, timeouts, and an honest merge. Get those right and the speed-up is real.

Search topics

↑↓ to move · Enter to open · Esc to close