skip to content

When a hosted workflow engine fans one step out over thousands of items, what do you configure to protect downstream services and the fan-in?

level: middleimportance: must knowfreq 50%

answer

  1. the slowest dependency sets the pace
  2. a cap on parallel branches
  3. references, not payloads
  4. retry per item, idempotent steps
  5. batch large fans into child executions

basics

~20 s

Cap the fan-out's parallelism at what downstream services and the function concurrency quota can absorb, pass storage references instead of payloads, give each item a retry policy with idempotent steps, and batch very large fans so the fan-in stays bounded.

solid answer

~50 s

A fan-out runs the same step once per item (each page of a large upload, say) and a **fan-in** waits for all branches and combines their results. Configure: a **maximum concurrency** on the fan-out, sized to the tightest downstream (a rate-limited text-extraction service, a database, the function's concurrency cap), because an unbounded fan-out turns one execution into a burst that throttles everything else; **per-item retries with backoff**, which only works if each item's step is **idempotent**; a decision on **partial failure**, either failing the whole run or tolerating some failed items where the engine supports that; and **small results**: each branch writes its output to storage and returns a key, because most engines cap the data passed between steps and the fan-in would otherwise overflow it. For very large fans, batch items into child executions so no single history grows without bound.

code

yaml · 10 lines
yaml
extractPages:
  type: forEach
  items: "{{input.pageKeys}}"
  maxConcurrency: 40
  itemRetry:
    attempts: 3
    backoff: exponential
  onItemFailure: recordAndContinue
  itemResult: "storage key only"
  next: assembleDocument

go deeper

for a junior

Recall that a fan-out runs one branch per item in parallel and a fan-in waits for all branches before the workflow continues.

for a middle

Explain each setting: concurrency cap from the tightest dependency, per-item retries, idempotent steps, a partial-failure policy, and storage keys instead of payloads.

for a senior

Show how you would diagnose a fan-out that throttled a dependency or broke the fan-in at scale, and how you re-run only the failed items.

for a principal

Weigh per-step engine cost against batching work inside functions, and set a default concurrency policy that protects shared dependencies across teams.

## What fan-out and fan-in mean in a hosted workflow A **fan-out** step takes a list and runs the same sub-step once per item, in parallel. A **fan-in** is the point where the workflow waits for every branch to finish and combines what they produced. In a document pipeline, an uploaded scan of a few thousand pages fans out to one text-extraction branch per page, and the fan-in assembles the pages into one searchable document before review. Fan-out is where a single workflow execution turns into many concurrent function invocations, so it is where a workflow most easily hurts things around it. ## The settings that matter | Setting | What it protects | Symptom when missing | |---|---|---| | Maximum concurrency on the fan-out | Downstream services and the function concurrency quota | Throttling errors, a rate-limited dependency, other functions starved | | Per-item retry with backoff | Individual items against transient failures | One flaky page fails the whole document | | Idempotent item steps | Correctness under retries and redelivery | Duplicate rows, double charges, pages extracted twice | | Partial-failure policy | The run's outcome when a few items fail | All-or-nothing behaviour nobody chose | | References instead of payloads | The engine's cap on data passed between steps | The fan-in fails on payload size at production scale | | Batching into child executions | Execution history and fan-in size | A history that hits the engine's event cap | ## Sizing the concurrency cap An unbounded fan-out asks the platform for as many parallel invocations as there are items. That rarely ends well, because the function platform is not the only limit in play: 1. Find the **tightest dependency** each branch calls: an external extraction service with a request-rate limit, a database with a connection ceiling, a third-party API with a request quota. 2. Convert its limit into concurrency. A dependency that handles a known rate, called by branches that each take a known time, supports roughly rate times duration branches at once. 3. Leave room for everything else that shares the same **regional concurrency quota** and the same dependency, such as the live API. 4. Set the fan-out's maximum concurrency below that figure and measure throttling during a realistic load test, not a ten-item demo. The cap trades total run time for stability: a document takes longer to extract, and nothing else falls over while it does. ## Failures inside a fan-out - Give each item step its own **retry policy with exponential backoff**, so a transient error retries that item rather than the whole run. - Make each item step **idempotent**. Retries, redelivery and a re-run after a fix can process the same page more than once; writing results under a deterministic key (document and page number) makes a second run harmless. - Decide the **partial-failure policy** deliberately. By default many engines fail the whole fan-out as soon as one branch fails. Some let you tolerate a share of failed items; elsewhere you catch per-item errors inside the branch and record them. For a scanned book, a page marked "extraction failed, send to manual review" is usually better than discarding a document of thousands of pages. - After a fix, **re-run only the failed items** rather than the whole list, which is cheaper and easier if every branch wrote its outcome to storage. ## Keeping the fan-in bounded - **Return references, not data.** Each branch writes its extracted text to object storage and returns a small key. Most engines cap the size of data passed between steps, and a fan-in that collects thousands of full results breaks that cap in production even if a small test passed. - **Batch large fans.** Group items into batches and run each batch as a **child execution**. The parent's history then records one event per batch instead of several per item, staying under the event cap many engines enforce. - **Assemble from storage.** The fan-in step reads the keys, not the content, and builds the final document from object storage. - **Watch per-step cost.** On engines priced per step, every branch and every retry is billed; a fan-out of thousands of single-item branches can cost more than batches that each handle many items inside one function.

  • How do you choose the number for a fan-out's maximum concurrency?
    Start from the tightest dependency the branch calls. Its sustainable request rate multiplied by how long each branch holds a request gives the concurrency it can absorb. Subtract headroom for other callers sharing that dependency and the regional concurrency quota, set the cap below the result, and confirm it with a load test at production volume while watching throttles and downstream errors.
  • Why can a fan-out that passed testing fail on its first large production run?
    Tests usually fan out over a handful of items. At production size the fan-in collects far more results than the engine's cap on data passed between steps allows, the history approaches its event cap, and the burst of branches meets quotas and rate limits a small run never touched. Returning storage keys, batching into child executions and testing at realistic volume catch all three.
  • What does batching items inside each branch change compared with one branch per item?
    Fewer branches mean fewer engine steps to pay for and a shorter history, and each function invocation amortises its start-up across many items. The cost is coarser retries: a failure retries the whole batch, so the per-item work must be idempotent and the batch small enough to finish well inside one function's time limit.

  • Leave the fan-out unbounded because the function platform scales to whatever is needed.
  • Return each branch's full extracted text and join it all in the fan-in step.
  • The engine's retries make item steps safe even if they are not idempotent.
  • The fan-out's concurrency cap and the regional concurrency quota are the same setting.
  • One failed page must always fail the whole document; there is no middle ground.