Add a Promise.all Concurrency Limit to Stop 429 Errors
Wrapping an array of requests in Promise.all executes every operation on the same event-loop tick, which triggers HTTP 429 errors. You fix this by using a bounded worker pool pattern to cap active operations.
On this page
Wrapping an array of asynchronous requests in Promise.all executes every operation on the exact same event-loop tick. Because JavaScript provides no native promise.all concurrency limit, dispatching hundreds or thousands of tasks at once exhausts socket descriptors, drains database connection pools, and triggers instant HTTP 429 Too Many Requests errors.
You fix this by replacing unbounded execution with a bounded worker pool pattern that caps active operations to a fixed threshold, queuing remaining tasks until an active slot frees up.
A community discussion on DEV Community published on 20 November 2026 titled "Stop Wrapping Everything in Promise.all: How Unbounded Concurrency Crashes APIs" highlighted this exact breakdown, generating 21 reactions and 10 comments from developers facing production outages. The core problem is structural: Promise.all does not provide an execution throttle. Passing an array of 2,000 asynchronous fetch calls to Promise.all tells Node.js to initialize 2,000 simultaneous network operations immediately.
The mechanics of unbounded event-loop execution#
JavaScript runs single-threaded code on an event loop. When you invoke an asynchronous function, Node.js hands off the I/O operation to the system kernel or the internal thread pool, registers a callback, and moves immediately to the next synchronous instruction.
When developers write await Promise.all(items.map(fetchData)), they often assume the runtime manages the workload responsibly. It does not. JavaScript iterates through the entire array synchronously, executes every function call, and registers every promise on that single event-loop tick.
This behavior creates concurrency, not true parallelism. In Node.js, multiple asynchronous I/O operations interleave across the single-threaded event loop rather than running on separate CPU threads. If the input array contains 1,000 items, your application opens 1,000 simultaneous TCP sockets within milliseconds.
Downstream rate limiters detect this traffic pattern as an abnormal spike or a denial-of-service attempt. The remote API immediately responds with HTTP 429 Too Many Requests status codes. If you hit your own internal database instead of a remote API, the burst instantly claims every available slot in your connection pool, forcing subsequent application queries to wait, time out, and crash.
How unbounded concurrency breaks infrastructure#
The damage from unbounded concurrency rarely stays confined to a single route. It creates an infrastructure ripple effect that cascades through internal microservices.
Unbounded Promise.all
│
▼ (1,000 concurrent requests on 1 tick)
[ Socket Descriptor Exhaustion ]
│
├───────────────────────────────┐
▼ ▼
[ External APIs (HTTP 429) ] [ Database Pool Starvation ]
│ │
▼ ▼
[ Single Promise Rejection ] [ Query Timeouts & Leaks ]
│ │
└───────────────┬───────────────┘
▼
Cascading Service Outage
When an application opens hundreds of simultaneous connections, the operating system allocates a socket descriptor for each open handle. If your process reaches the system limit for open file descriptors, it cannot create new connections, serve new incoming web requests, or read from disk.
Heap memory consumption climbs simultaneously. Each pending promise, closure context, and network buffer remains pinned in memory until the operation completes or fails. Under heavy production loads, this memory pressure triggers aggressive garbage collection pauses, which starves the event loop of processing time.
The failure mechanism of Promise.all makes this worse. Under MDN specifications, Promise.all rejects immediately when any single promise rejects. If 999 requests succeed but request number 1,000 receives a 429 rate limit or drops a socket connection, Promise.all drops everything and rejects the entire batch. All the work performed by the successful tasks is lost unless you handled errors individually on every call.
Evaluating concurrency patterns#
Different concurrency patterns handle load, errors, and throughput in distinct ways. The right pattern depends on whether you control the downstream resource and how individual errors should be handled.
| Approach | Concurrency Behavior | Risk of 429 / Crash | Error Handling Behavior | Best Used For |
|---|---|---|---|---|
Promise.all |
All tasks executed instantly on the same tick | Extremely High (Instant spike) | Fails fast on first rejection | Small, fixed arrays of trusted, local operations |
Promise.allSettled |
All tasks executed instantly on the same tick | Extremely High (Instant spike) | Never fails fast; returns outcome objects for all | Batch operations where individual failures are acceptable |
Bounded Worker Pool (p-limit) |
Restricted to $N$ active tasks simultaneously; queues the rest | Low to Zero (Controlled flow) | Depends on implementation (Promise.all or allSettled on wrapped tasks) |
Bulk database queries, web scraping, third-party API enrichment |
Promise.allSettled eliminates the fail-fast problem by waiting for every promise to settle, returning an array of status objects. However, it executes tasks with the same unbounded concurrency as Promise.all. It fires every request on the same tick, meaning it offers zero protection against rate limits or connection pool exhaustion.
The javascript worker pool pattern solves the root cause. Instead of launching all operations at once, it introduces a queue. The pool maintains a strict ceiling of $N$ actively executing tasks. The remaining operations wait in memory as unresolved functions until a running task completes, freeing a slot.
Implementing bounded concurrency with p-limit#
You can build nodejs concurrency control into your application using utility packages from the npm registry such as p-limit or async. For most projects, p-limit is the cleanest option because it wraps promise-returning functions directly.
To install it:
npm install p-limit
This pattern demonstrates how to fix 429 errors api calls by limiting concurrent work to five operations at a time:
import pLimit from 'p-limit';
const limit = pLimit(5);
const inputs = [/* 1000 items */];
const tasks = inputs.map(item => limit(() => fetchItemData(item)));
const results = await Promise.all(tasks);
In this implementation, inputs.map does not execute fetchItemData immediately. Instead, it passes a closure returning the promise to limit. The p-limit instance acts as a gatekeeper, running five calls simultaneously. As each call resolves, the next task in the array begins.
If you need the batch to continue processing even when individual requests fail, combine the bounded pool with Promise.allSettled:
import pLimit from 'p-limit';
const limit = pLimit(10);
const inputs = [/* 1000 items */];
const tasks = inputs.map(item => limit(() => fetchItemData(item)));
const results = await Promise.allSettled(tasks);
Using Promise.allSettled ensures that network errors or individual 429 responses will not discard successfully retrieved data from other items in the batch.
Step-by-step rollout for bounded concurrency#
Eliminating unbounded concurrency from a production codebase requires a structured approach across your data layer and API calls.
- Identify unbounded concurrency points: Search your codebase for
.map()operations combined directly withPromise.allorPromise.allSettled. Pay attention to dynamic inputs, such as arrays populated by database queries or user uploads, where an input array could grow from 10 items in local testing to 10,000 items in production. - Determine your concurrency threshold: Check the limits of the downstream system. If your database connection pool maxes out at 20 connections, your concurrency ceiling for batch database queries must stay well below 20 to leave headroom for transactional web traffic. If an external API enforces an intake limit of 10 requests per second, configure your pool to 5 or 10 concurrent tasks. Safe starting thresholds usually sit between 5 and 50 tasks.
- Choose a concurrency library or pattern: Use an established npm utility like
p-limitorasyncto avoid edge-case bugs around unhandled rejections and memory leaks. If company policy forbids third-party dependencies, implement an in-house async queue using arrays and generator functions orAsyncResource. - Wrap asynchronous operations: Refactor your mapped promises into worker-wrapped task functions. Ensure the asynchronous function is executed inside the limiter wrapper, not before passing it into the limiter.
- Handle batch rejections: Decide whether a single failed task should abort the entire batch. If individual failures are tolerable, use
Promise.allSettledon the wrapped tasks and filter the output array by status. - Monitor and adjust: Watch your database connection pool metrics, memory allocation, and outgoing HTTP status codes. If you still encounter 429 errors or connection pool starvation, step the concurrency ceiling down. If downstream utilization stays flat and latency is acceptable, you can gradually increase the threshold.
If you are standardizing your API deployment pipelines alongside client stability, follow our guide on how to deploy a secure API in 30 minutes.
Common mistakes in custom concurrency implementations#
When engineers decide to build concurrency limits without libraries, several implementation traps appear frequently.
The most common mistake is confusing concurrency with multi-threaded parallelism. Developers sometimes believe that moving tasks into a custom worker loop will utilize multiple CPU cores. In Node.js, asynchronous I/O concurrency still runs on the primary thread. If you introduce a heavy, blocking synchronous loop inside your task runner to manage a queue, you block the event loop entirely.
Another frequent failure is improper error propagation. When developers write custom queues using array slicing or recursion, they often forget to attach catch handlers to the promise lifecycle inside the worker function. An unhandled promise rejection inside a custom worker pool will trigger a process-level termination in modern Node.js versions, turning a manageable downstream error into an application crash.
Finally, teams often look exclusively at external third-party services when investigating HTTP 429 status codes while ignoring internal database pools. A microservice running an unbounded Promise.all loop against a PostgreSQL or MySQL cluster can exhaust database pool limits just as easily as an external vendor API. Connection pools are finite resources. Treating them as unlimited queues leads to cascading timeouts across every service connecting to that database.
Frequently asked questions#
Why does Promise.all cause 429 Too Many Requests errors?#
Promise.all triggers all underlying asynchronous calls simultaneously in a single batch on the same event-loop tick. This sudden burst of hundreds or thousands of simultaneous connections overwhelms external rate limiters and database connection pools instantly.
How do I limit concurrency in Node.js without third-party libraries?#
You can build a custom worker pool using an array as a task queue, tracking the count of active workers and triggering the next item upon completion using recursive promises or generator functions. You must attach error handlers inside the worker execution loop to avoid unhandled rejections.
What is the difference between Promise.all and Promise.allSettled with a worker pool?#
Promise.all rejects immediately if any single task fails, discarding the overall operation unless individual errors are caught. Promise.allSettled waits for all queued tasks to finish regardless of success or failure. Both execute simultaneously by default, but both can be combined with a worker pool to restrict active operations to a fixed limit.
Does Promise.all run in parallel or concurrently?#
In JavaScript's single-threaded event loop, Promise.all runs operations concurrently by interleaving asynchronous I/O callbacks. It does not run true parallel multi-threaded CPU execution unless combined with Worker Threads or child processes.
What to do next#
Audit your services for any instance where Promise.all consumes dynamic arrays. Install p-limit, establish concurrency limits based on your database pool sizes and external API quotas, and wrap batch network calls before your next high-volume batch job runs.