At 02:14 UTC, a scheduled billing job ran await Promise.all(invoices.map(syncInvoice)) across 1,200 customer records. Within 400 milliseconds, the payment gateway returned 429 Too Many Requests, PostgreSQL threw connection pool timeouts, and 1,199 completed writes became orphaned because the final promise rejected.
Most JavaScript and TypeScript developers reach for Promise.all whenever an array of async tasks needs to run faster, assuming the runtime will schedule those tasks responsibly. It will not.
How Array.map() Turns Promise.all Into a Traffic Spike
When replacing a slow sequential for...of loop, the standard reflex is mapping an array of IDs directly into Promise.all(ids.map(fetchUser)). In local development with 5 mock records, this pattern looks clean and passes every test. In production with 5,000 records, it becomes a self-inflicted denial-of-service attack.
The bug stems from confusing synchronization with scheduling. Promise.all does not throttle or queue execution. Because Array.prototype.map() is synchronous, Node.js invokes every async callback on the exact same tick of the event loop. Before Promise.all even receives the array of promises, the runtime has already initiated 5,000 concurrent DNS lookups, TLS handshakes, socket buffers, and database queries.
Three Ways Unbounded Concurrency Breaks Production
In my production audits, firing unbounded promise arrays consistently triggers three cascading failure modes:
- Downstream Thundering Herd: External APIs enforce strict rate limits, and relational databases typically cap connection pools between 10 and 50 connections. Opening 1,000 concurrent requests saturates the pool immediately and starves unrelated endpoints.
- Fail-Fast Orphaned Side Effects:
Promise.allrejects the instant one promise fails, but JavaScript promises do not cancel automatically. The remaining 999 HTTP calls and database mutations keep mutating state in the background with nothing awaiting their completion. - V8 Heap and GC Stalls: Buffering thousands of raw response streams and parsed JSON payloads simultaneously causes sharp memory spikes, triggering stop-the-world garbage collection pauses or container OOM kills.
Capping Active Promises With a Bounded Worker Pool
To measure the difference in a reproducible benchmark, I ran 200 simulated 50ms requests against a downstream service capped at 10 concurrent connections (returning HTTP 429 above 10). Unbounded Promise.all crashed in 52ms with zero completed tasks, while a bounded worker pool finished all 200 tasks in 1,045ms—nearly 10x faster than a sequential loop without dropping a single request.
Instead of firing every task at once, spin up N lightweight workers that pull from a shared index and wire an AbortController to stop queued work on fatal errors:
export async function mapWithConcurrency<T, R>( items: readonly T[], limit: number, workerFn: (item: T, signal: AbortSignal) => Promise<R> ): Promise<R[]> { const results = new Array<R>(items.length); const controller = new AbortController(); let cursor = 0; const workers = Array.from({ length: Math.min(limit, items.length) }, async () => { while (!controller.signal.aborted) { const index = cursor++; if (index >= items.length) break; try { results[index] = await workerFn(items[index], controller.signal); } catch (err) { controller.abort(err); throw err; } } }); await Promise.all(workers); return results; } When syncing independent records where one failure should not abort the entire batch, catch errors inside workerFn and return { status: "fulfilled" | "rejected" } objects—mirroring Promise.allSettled while still honoring the concurrency ceiling.
Slicing an array into chunks of 10 and awaiting
Promise.all(chunk) in a loop prevents 429 errors, but introduces head-of-line blocking: 9 fast 20ms requests sit idle waiting for 1 slow 900ms outlier before the next batch begins. A shared worker pool keeps all 10 slots saturated continuously until the queue drains.Choosing the Right Concurrency Strategy
| Strategy | Max In-Flight | 200-Task Benchmark | Failure Behavior | Best Use Case |
|---|---|---|---|---|
Promise.all(items.map(...)) | Unbounded (N) | Failed at ~52 ms (HTTP 429) | Fail-fast without aborting in-flight work | Fixed tuple of 2–5 independent calls |
Promise.allSettled(items.map(...)) | Unbounded (N) | Spiked to 200 connections (HTTP 429) | Waits for all tasks; still floods downstream | Small, fixed tuple tolerating partial errors |
Sequential for...of | 1 | 10,180 ms (100% succeeded) | Halts on first error | Strict ordering or fragile single-threaded APIs |
Bounded Worker Pool (limit = 10) | 10 | 1,045 ms (100% succeeded) | Aborts remaining queue via AbortSignal | Dynamic arrays, DB batches, external API syncs |
The Takeaway
Promise.all works well for awaiting a small, known tuple of heterogeneous calls—such as loading a user profile, permissions, and feature flags during an API request. The moment the input becomes a dynamic array of unknown length, wrapping .map() in Promise.all turns into a reliability hazard. Cap concurrency explicitly so throughput stays high without overwhelming downstream services.
What failure mode have you seen in production when an unbounded Promise.all hit a database pool or rate-limited API?
Connect with Me
If you found this article helpful, let's connect!
- 💻 GitHub: johnnylemonny
Open to opportunities. Looking for commisions and collaborations.


