05. Design Patterns
Routing and Parallelization Patterns
Routing sends a request down one specialist path. Parallelization fans work out to many branches and joins the results. Together they cut cost, latency, and chaos in agentic systems.
What you will learn
- Define routing and parallelization clearly
- Design a router with fail-closed defaults
- Choose fan-out/fan-in join policies
- Know when not to parallelize
- Answer interview questions with short, solid answers
Definition
Routing is a control pattern that classifies an input (intent, risk, language, tenant) and directs it to a single downstream skill, agent, prompt chain, or tool set. Parallelization (fan-out/fan-in) starts multiple independent branches at once, then joins their outputs before continuing.
Routing optimizes relevance and cost. Parallelization optimizes wall-clock time and diversity of evidence β at the price of more tokens and join complexity.
Introduction
This lesson (#2 in Design Patterns) follows Prompt Chaining. Chains are linear; routing and parallelization add branch shapes you compose with chains and agent loops.
Next: Orchestrator-Worker and Evaluator-Optimizer β common multi-role uses of these ideas.
Why these patterns matter
- Avoid loading every tool into every prompt
- Speed independent research/critique steps
- Isolate permissions per route
- Make topology explicit for ops and evals
Routing pattern
A router can be rules, embeddings classifiers, or an LLM with a small label set. Prefer cheap routers when possible.
- Inputs - user text, metadata, risk scores
- Output - one route id + confidence
- Downstream - specialist prompts, tools, or agents
- Fail closed - unknown β escalate or generalist with limited tools
- Log - route, confidence, and chosen edge for audits
Parallelization pattern
Split only when branches do not fight over the same mutable resource.
- Fan-out - create N independent tasks/calls
- Workers - same prompt on shards, or different specialists
- Join - aggregate with an explicit policy and timeout
- Synthesize - LLM or code merges into one artifact
- Caps - max concurrency and max parallel token spend
Join policies
- Wait-all - need every branch (default for synthesis)
- Wait-n - proceed when n of m succeed
- First-success - race redundant providers; cancel losers
- Best-of - score candidates and keep the winner
- Partial OK - continue with warnings if some branches fail
Routing vs parallelization β choose
- Route when intents need different tools/policies
- Parallelize when subtasks are independent and latency matters
- Do both - route first, then parallelize inside a route
- Avoid parallelizing conflicting writes (use sequential + locks)
Failure modes
- Misrouting - wrong specialist; mitigate with confidence thresholds
- Route thrash - oscillating labels; sticky session or hysteresis
- Join deadlock - waiting forever; always set join timeouts
- Cost blowups - unbounded fan-out; cap N and token budgets
- Partial merge bugs - treat missing branches explicitly
Program / implementation notes
Implement routers as pure functions returning enums. Implement parallel steps with a concurrency limiter and structured per-branch errors.
- Eval routers with a labeled intent set offline
- Trace branch_id through join for debugging
- Prefer code merges for deterministic joins; LLM for synthesis prose
- Next: Orchestrator-Worker and Evaluator-Optimizer Patterns
Advantages and limitations
- Advantage: cheaper, sharper tool context via routing
- Advantage: lower latency via parallel gathers
- Advantage: clearer multi-skill architectures
- Limitation: router errors send users down wrong paths
- Limitation: parallel joins add complexity and spend
- Limitation: naive fan-out can DDoS your own APIs
Key points
- Routing selects one downstream path from a classification.
- Parallelization fans out independent work then joins.
- Fail closed on unknown routes; timeout joins.
- Pick join policy deliberately (wait-all / wait-n / first-success).
- Compose: route first, parallelize inside a route when useful.
- Cap concurrency and spend on every fan-out.
FAQs
Is an LLM router always required?
No. Rules or small classifiers are often better for stable intents. Use an LLM router when labels are fuzzy and volume justifies the cost.
Parallel tool calls vs parallel agents?
Same fan-out idea. Tool calls stay in one agent; parallel agents add separate policies/roles. Choose based on isolation needs.
How is routing different from conditional workflows?
Routing is the pattern name for that conditional branch at the skill/agent layer β same family as the conditional workflow shape.
When should I not parallelize?
When steps share mutable state, must stay ordered, or when extra branches would exceed budget without quality gains.
Interview questions
- What is the routing pattern in Agentic AI?
Answer A pattern that classifies an input and sends it to one specialized prompt, tool set, or agent path.
- What is parallelization in agent design?
Answer Running independent branches concurrently (fan-out) and merging results (fan-in) to reduce latency or gather diverse evidence.
- When do you route instead of giving one agent all tools?
Answer When different intents need different permissions, prompts, or models β routing reduces confusion and cost.
- Name join policies for parallel work.
Answer Wait-all, wait-n, first-success, best-of scoring, and partial-success with warnings β each needs a timeout.
- How do you handle unknown router labels?
Answer Fail closed to an escalate/safe-default path rather than guessing a privileged specialist.
- Give a combined example.
Answer Route βresearchβ vs βrefundβ; on research, parallelize three source fetches, join wait-all, then draft.
- What are risks of aggressive parallelization?
Answer Higher token/API cost, rate-limit storms, and subtle merge bugs when some branches fail.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- List 6 intents for a support product and the route each should take.
- Define a fail-closed behavior for low-confidence routing.
- Design a 3-branch parallel research fan-out with wait-all and a 20s join timeout.
- Mark two steps in your product that must stay sequential (no parallel).
- Answer interview questions 1, 2, and 4 in two sentences each.