← Effect fixes your TypeScript

Effect fixes your TypeScript · Part 5

Promise.all just DDoSed your own API

· by Tony Tang

Promise.all over 10,000 IDs fires 10,000 requests in the same tick, and when one fails the others keep running. Effect.forEach with concurrency: 10 keeps ten in flight and interrupts the rest on failure.

Comment below: What's the biggest Promise.all you've ever shipped?

Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website

Transcript

Promise.all just DDoSed your own API. ids.map(getUser) inside Promise.all. Looks innocent. With 10,000 IDs, that's 10,000 requests in the same tick. Your connection pool chokes, the rate limiter kicks in, and the first failure rejects the whole thing while the other requests keep running. Nobody's listening to them anymore. In Effect, Effect.forEach(ids, getUser, { concurrency: 10 }): 10 in flight, never more. And if one fails, the others are interrupted, not abandoned. Need more throughput? Change one number. Concurrency is a parameter, not an architecture. Best practice, every fan-out gets a limit. Unbounded is a bug that hasn't happened yet. Interrupted, remember that word because your timeouts don't actually cancel anything. Part six, what's the biggest Promise.all you've ever shipped?

Full lesson in the Learn Effect course ↗ Zip, concurrency you opt into

More from this series