Parallelization
Also known as: fan-out / fan-in, scatter-gather, concurrent orchestration
- Who decides
- Code
- Shape
- Fan-out
Intent
Run several LLM calls at the same time on pieces of work that do not depend on each other, then combine their outputs in one aggregation step. Your code fixes the split before the run starts: either different subtasks in each branch (sectioning) or the same task run several times (voting).
Problem
You are building a due-diligence tool for a small investment team. An analyst uploads the data room of Acme Robotics (corporate documents, three years of financial statements, the main customer contracts, a market study) and asks: “Is Acme a reasonable acquisition target?”
The answer needs a legal review, a financial review and a market review. None of them needs the others’ output. The first versions of the tool break in three ways:
- The reviews run one after the other. Each review is its own prompt, but the code waits for each one before starting the next. At about 20 seconds per review, the analyst waits a minute for work that has no reason to be sequential.
- One prompt does all three jobs. Merging the reviews into one call is faster, but the model now reads contracts for change-of-control clauses, checks revenue figures and judges competitors in the same pass. Each concern gets less attention, and the legal findings are the first to thin out.
- One reading is trusted blindly. When a single call misreads a clause, nothing catches it, and the report gives no hint of how sure it is.
Solution
Write the split in code. Start one LLM call per independent piece at the same time, wait for them at a barrierBarrier A point in the code that waits until every task it started in parallel has finished, or a deadline has passed, before going on., then hand all the results to one aggregator. Each branch sees only its own prompt and the shared input; branches never talk to each other while they run.
On the Acme data room, a run looks like this:
- Split. Code builds the list of branch tasks:
legal_review,financial_reviewandmarket_review, each with its own focused prompt and the same data room. - Fan out. All three calls start together, with a limit on how many run at once and a timeout for each.
- Review. Each branch returns its findings in a fixed format: what it found, how serious it is, and the document that shows it. The legal review flags a customer contract that ends on a change of control.
- Fan in. A barrier waits until every branch has finished or timed out. All three reviews came back; had one timed out, the barrier would record it as missing.
- Aggregate. One more LLM call merges the three reports into a risk summary. It keeps every distinct risk, says which review raised it, and states where two reviews disagree.
- Return. The analyst gets the summary about 25 seconds after uploading, with a line saying all three reviews completed.
That run is sectioning. With voting, three branches would each read the same contracts for change-of-control clauses, and code would flag a clause if any of them reports it. The nearest pattern, Orchestrator–Workers, has the same fan-out shape, but there a lead model decides at run time how many subtasks exist and what each covers; here your code wrote the list before the run.
Structure
Hover over a number, or tap it, to read what it is.
- Splitter. Code that turns the input into a fixed list of branch tasks, each with its own prompt. It is written before the run, and no branch’s task depends on another’s result.
- Branches. One LLM call per subtask or per sample, started at the same time under a concurrency limit and a timeout. Each returns its result in a known format and never sees the other branches.
- Fan-in barrier. Waits for every branch, a quorum or a deadline, and records which branches succeeded and which failed.
- Aggregator. Turns the branch outputs into one result, either with plain code (a union, a majority vote, a k-of-N threshold) or with one more LLM call that writes a synthesis.
- Result with branch status. The merged answer, plus which branches completed, whether the result is missing a part, and for voting the vote counts.
Use it when / Avoid it when
Use it when
- The subtasks are truly independent. No branch needs another’s output, and the order in which they finish does not matter.
- Latency matters. The run takes as long as the slowest branch plus the merge, instead of the sum of all branches.
- One prompt is juggling several concerns. A safety check beside the main answer, or one grader per quality criterion, each gets a call of its own.
- You need a more reliable answer or a confidence signal. Voting works when answers have a comparable form (a label, a number, a choice), and the vote margin says how sure to be.
Avoid it when
- The steps depend on each other. Use Prompt Chaining, which passes each step’s output to the next.
- You cannot list the subtasks in advance. Use Orchestrator–Workers, where a lead model decides the split at run time.
- Branches would write to the same record or system. Use a single call or a chain for the writes, or keep every write in the aggregator, because concurrent branches overwrite each other.
- The budget or the rate limit is tight. Use a single call: voting multiplies the cost by the number of branches, and one good call may already be enough.
How it fails
- Hidden dependency
-
One branch needed a fact another branch found, and their reports contradict each other with no way for the merge to tell why.
Mitigation: draw the dependencies between subtasks before building, and chain any two that are linked.
- Silent partial failure
-
One branch errors and the aggregator merges the rest as if nothing happened, so a section is missing or a vote is skewed.
Mitigation: choose a failure policy up front (fail the run, require a quorumQuorum The minimum number of branches that must succeed for the result to count, such as 3 of 5., or mark the result as incomplete) and have the aggregator write “not available” for a missing part.
- Rate-limit storm
-
All branches start at once, many get HTTP 429 errors, and immediate retries make the burst worse.
Mitigation: cap concurrency below the provider’s limit and retry with exponential backoff.
- Correlated errors
-
Every vote shares the same mistake, so the majority is confidently wrong, and adding votes only adds cost.
Mitigation: vary the branches (different prompts, shuffled answer options, different models), or check answers with tests where you can.
Related patterns
- Prompt Chaining: the sequential counterpart, for steps that depend on each other; the two often combine as a chain that prepares the input, a parallel stage, then a merge.
- Routing: picks one branch per input, where parallelization runs several.
- Orchestrator–Workers: the same fan-out and fan-in, but a lead model writes the list of subtasks at run time.
- Council / Debate: members read and answer each other before deciding, while voting keeps every sample independent; cost-matched voting is the baseline a council should beat.
Try it
Describe the shared input and one row per branch. The generator writes a prompt for each branch, the aggregator prompt or rule, and a run spec for your fan-out code: limits, failure policy and aggregation rule.
Open the generator on this pattern
Further reading
- Building effective agents (Anthropic, 2024): defines parallelization, sectioning and voting, with guardrail and code-review examples.
- Self-Consistency Improves Chain of Thought Reasoning in Language Models (Wang et al., 2022): the voting method and how to aggregate the samples.
- Are More LLM Calls All You Need? (Chen et al., 2024): why more votes can lower accuracy, and how to choose the number of calls.