← All topics
Knowledge

Parallelization: fan out independent work

Parallelization runs independent sub-tasks concurrently — split-and-merge for speed, or same-task-N-ways for accuracy — but only when no step depends on another's output.

What it is

Parallelization runs work that has no data dependency at the same time instead of one step after another. Two shapes:

  • Sectioning: split one job into independent sub-tasks, run them concurrently, merge the results.
  • Voting: run the *same* task several ways (or several times) in parallel, then aggregate — majority vote, best-of-N, or a judge.

If step B needs step A's output, that's prompt chaining, not this.

When to use it

Reach for it when latency or coverage matters and the pieces don't depend on each other:

  • Sectioning: summarize 10 documents, call 3 unrelated APIs, score one input on safety + tone + relevance at once.
  • Voting: generate 5 answers and take the majority for a flaky reasoning task; or run strict + lenient graders and combine.
  • Pair it with routing to dispatch each branch to the right model.

Don't use it when one step feeds the next, or when fan-out cost outweighs the time saved.

How it works

You launch N calls together, wait for all to finish, then combine. Sketch with Promise.all:

  • Build independent prompts: tasks = [summarize(doc1), summarize(doc2), summarize(doc3)].
  • Fire them concurrently: results = await Promise.all(tasks) — wall-clock time is the slowest branch, not the sum.
  • Aggregate explicitly: concatenate sections, take a majority(results), or pass all outputs to a synthesizer step.
  • Decide failure policy per branch: one rejected branch shouldn't sink the batch unless it must (Promise.allSettled keeps partial results).

Watch out for

  • Fake independence: if branches secretly share state or order matters, parallel runs produce subtly wrong merges. Confirm zero data dependency first.
  • Cost multiplies: voting N-ways is N times the tokens for one answer. Worth it for accuracy, brutal on your bill — see cost control.
  • The merge is the hard part: aggregation logic (dedupe, conflict resolution, tie-breaking) is where bugs hide, not the fan-out.
  • Partial failure: one branch timing out shouldn't silently drop from the result — handle it, log it (see observability).

Related patterns

Ask the swarm