What do you think of this? <URL> Uploaded an image
- User
What do you think of this?
Uploaded an image
- Assistant
What do you think of this?
Uploaded an image
Punch‑line firstThe lesson (“don’t fireawaitone‑by‑one when the calls are independent—usePromise.all”) is perfectly solid. The tweet’s numbers, however, smell like the usual social‑media exaggeration: shaving 19 seconds down to 90 ms implies each call was ~90 ms and they were being stacked three‑deep. Possible? Sure. Typical? Not if you’re calling real‑world services that each spend 200‑600 ms on the wire.
What the tweet gets right
['✅ Principle', 'Why it matters'] ['Async ≠ parallel.awaitsuspendsthiscoroutine until the promise resolves; stackedawaits serialize otherwise independent work.', 'Junior devs often conflate “async” with “concurrent”. Seeing “await” in front of every line is a reliable latency smell.'] ['Promise.allas the blunt hammer.Fire off promises, then await the composite once. Dead simple, and for many CRUD‑style aggregations that’s all you need.', 'Works in browsers, Node, Deno, Bun, Cloudflare Workers—no fancy libs required.'] ['Big wins are often hidden in small code changes.A nice managerial “mentor” story.', 'Good for morale and code reviews.']
What’s conveniently glossed over
['⚠️ Caveat', 'Why you (as a PM/tech‑lead) should care'] ['The 90\u202fms fairy‑tale.If each call is to the same backend, three simultaneous requests can contend for the same DB row, cache key, connection pool, etc. Realistic speed‑up is “the slowest request” + a little overhead—not 90\u202fms flat.', ''] ['Error behaviour changes.In serial code,fetchB()never runs iffetchA()throws. InPromise.all, everything fires; if any promise rejects, the composite rejects immediately. You must decide whether that’s acceptable or switch toPromise.allSettledand handle partial results.', ''] ['Rate limits & quotas.Parallelising five Gmail API calls is fine; parallelising 500 will get you a 429. Guard with a concurrency pool (p‑limit, Bottleneck) or batch at the server.', ''] ['Back‑pressure and retries.Hammering micro‑services in parallel can amplify tail‑latency. Sometimes the right optimisation isfewerrequests (e.g., aggregate behind a BFF, move the join to the database, or adopt GraphQL).', ''] ['CPU‑bound work isn’t fixed byPromise.all.If the bottleneck is JSON parsing or crypto, you need workers/threads or SIMD, not “more promises”.', '']
Deeper patterns worth teaching the junior dev
Concurrency budget:Decide on an upper bound (e.g., 5–10 outstanding requests) and use a queue. Prevents self‑DoS under load.
Staged pipelines:Kick off independent I/O in parallel, but still await early results you need to compute request B’s inputs.
Cancellation tokens /AbortController:If one request’s failure makes the whole composite pointless, abort the in‑flight siblings to free resources.
Observability:Record fan‑out counts, per‑service latencies, and “parallel savings” as custom metrics. Lets you catch hidden sequential paths in prod.
Move joins left:When feasible, let the upstream service fan‑in. Round‐trips beat parallelisation only in small numbers.
Concurrency budget:Decide on an upper bound (e.g., 5–10 outstanding requests) and use a queue. Prevents self‑DoS under load.
Staged pipelines:Kick off independent I/O in parallel, but still await early results you need to compute request B’s inputs.
Cancellation tokens /AbortController:If one request’s failure makes the whole composite pointless, abort the in‑flight siblings to free resources.
Observability:Record fan‑out counts, per‑service latencies, and “parallel savings” as custom metrics. Lets you catch hidden sequential paths in prod.
Move joins left:When feasible, let the upstream service fan‑in. Round‐trips beat parallelisation only in small numbers.
The meta‑take
Tweets like this farm likes because they give a dopamine‑hit of “aha, junior mistake—I’d never do that!” But in real systems,latency work involves as much architecture as syntax: data‑model design, service boundaries, caching strategy, and capacity planning. ThePromise.alltrick is the first rung on that ladder, not the top.
Your turnWhere in your current codebase or product flow are you still paying a “serial tax”? If you want, drop a snippet and we can hunt for hidden latency dragons together.
Not yet included in a published release.