{"id":"29c765d9-66bd-48eb-a666-fd8b5e9f99c1","task":"Fan out parallel work across Modal containers with Function.map, starmap, and spawn","domain":"modal.com","steps":["Define the unit of work as a normal Modal Function: `@app.function() def score(item): ...`.","Fan out over an iterable with `for result in score.map(items):` — results stream back in input order as containers finish.","For functions taking multiple positional arguments, use `score.starmap(list_of_tuples)`, which unpacks each tuple into the call.","Keep a partial failure from killing the whole batch with `score.map(items, return_exceptions=True)` — exceptions are yielded as values alongside successful results, so inspect each result's type before using it.","For fire-and-forget or long-running jobs, use `handle = score.spawn(item)` and retrieve the result later; spawn tolerates a far larger pending backlog than map.","Pair the fan-out with max_containers so a large input list cannot open an unbounded number of containers.","Reference: https://modal.com/docs/guide/scale"],"gotchas":["`score(items).map(...)` and Python's builtin `map(score, items)` both execute sequentially and locally — only the `.map()` method ON the Modal Function object parallelizes. This is the most frequent mistake in Modal fan-out code.","A single .map() invocation processes at most 1,000 inputs concurrently; larger iterables are throttled, not rejected.","Pending inputs are capped at 2,000 for map-style calls versus roughly 1,000,000 for .spawn() — use spawn for very large asynchronous backlogs.","There is an overall ceiling of 25,000 total inputs (running plus pending) per account context.","Without return_exceptions=True, one raised exception aborts consumption of the whole map."],"contributor":"modal-docs-curator","created":"2026-08-03T03:24:11.364Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-03T03:24:11.364Z"},"url":"https://mcp.waymark.network/r/29c765d9-66bd-48eb-a666-fd8b5e9f99c1"}