Skip to content
tezvyn:
Menu

Dynamic Fan-out/Fan-in Pipelines

MediumHow cards are made

Dynamic fan-out/fan-in spawns parallel tasks from runtime data, then gathers results. Use it when input counts vary, like processing a daily changing set of files. The footgun is a fan-in task that hangs waiting for branches lost to partial failure.

Why it exists

Static data pipelines force you to decide how many parallel branches you need before the pipeline runs. In production ML systems, the amount of work is rarely constant. One day you might have three customer segments to retrain on, the next day thirty. Hard-coding branch counts wastes compute when load is low and breaks when load is high. Dynamic fan-out/fan-in exists so that the pipeline can match its width to the actual workload discovered at runtime.

The mental model

Think of a distribution center that does not know how many trucks will arrive each morning. Instead of building fifty fixed loading docks and leaving most empty, the center opens exactly one dock per truck that shows up, processes them simultaneously, and then closes them all once every parcel is back on a single outbound conveyor. The pipeline behaves the same way: it expands to fit the job, then contracts to deliver a unified result.

How it works

An initial task inspects the outside world, perhaps listing files in a landing bucket or querying a database for active experiment IDs. It returns a collection, such as a list of file paths or configuration dictionaries. The orchestrator then generates one parallel task per item in that collection, passing each item as input to its own branch. These branches run concurrently. A special fan-in task waits for the entire collection to complete and receives the outputs as an aggregated list or merged artifact. The key difference from static DAGs is that the graph structure is materialized at runtime, not defined ahead of time.

When to use it

Use dynamic fan-out/fan-in whenever the number of parallel units depends on data you cannot predict before the pipeline starts. Common scenarios include processing a variable number of daily partition files, running hyperparameter sweeps where the grid is generated by an upstream analysis, retraining one model per region or customer segment discovered in a metadata table, and embarrassingly parallel feature engineering across shards.

When not to use it

Avoid this pattern when the branch count can explode into the thousands, because most orchestrators store task metadata in a database that bloats with excessive task instances. Do not use it if the parallel branches need complex cross-communication or strict ordering, since the pattern assumes independence. Also skip it for very short tasks where scheduler overhead dominates runtime; in those cases, batch the work into fewer coarse branches instead.

One canonical example

A daily recommendation model pipeline wakes up and scans an S3 prefix for new user behavior logs. It discovers twelve parquet files today. The pipeline fans out to twelve parallel feature engineering tasks, each consuming one file and writing a processed shard. A fan-in task then collects all twelve shard paths, trains a single gradient boosted model on the unified dataset, and promotes the model to staging. Tomorrow the same pipeline might find three files or forty, and it will automatically adjust its width without any code changes.

Interview question

A pipeline must retrain one model per active customer segment, but that number changes daily. What advantage does dynamic fan-out/fan-in provide over a static DAG with a fixed number of branches?

  • a.It enables parallel branches to share intermediate state during training
  • b.It lets the pipeline discover segments at runtime and scale branch count to the actual daily workloadCorrect
  • c.It prevents orchestrator database bloat by limiting the total number of task metadata rows created per run
  • d.It guarantees that a failed segment will not block the final fan-in task from completing
Why?

The card explains that dynamic fan-out/fan-in materializes branch count at runtime based on actual data, eliminating the waste and rigid limits of static DAGs. Option D is tempting because it suggests resilience, but the card specifically warns that a fan-in task can hang indefinitely when branches are lost to partial failure.

Just read this? Test yourself on what you have been reading.

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on mlops — each one lists the topics its interview covers.

See open roles