In the modern landscape of web development, the efficiency and reliability of data fetching have become paramount. As applications evolve from simple pages into complex, data-driven dashboards, developers increasingly find themselves managing multiple concurrent requests. Whether it is retrieving user profiles, aggregating social media feeds, or pulling real-time analytics, the ability to handle these operations simultaneously is a hallmark of a high-performance application. However, for years, a significant challenge persisted in the way JavaScript handled multiple asynchronous tasks: the "all-or-nothing" trap.
The introduction of Promise.allSettled() as part of the ES2020 specification marked a pivotal shift in how developers approach these challenges. By providing a mechanism to wait for every task to complete regardless of its success or failure, this feature has become an essential tool for building resilient user interfaces that can withstand partial failures without compromising the entire user experience.
The Problem of the All-or-Nothing Approach
For much of JavaScript’s history following the introduction of Promises, Promise.all() was the standard method for executing multiple asynchronous operations in parallel. While powerful, Promise.all() operates on a "fail-fast" principle. If any single promise in the array rejects, the entire operation is immediately terminated, and the overall promise is rejected.
Consider the architecture of a typical administrative dashboard. To provide a comprehensive view to the user, the application might need to call three independent APIs simultaneously: one to fetch personal user information, another to retrieve a list of recent blog posts, and a third to pull site-wide statistics. Using the traditional Promise.all() approach, the implementation might look like this:
const [user, posts, stats] = await Promise.all([
fetch("/api/user").then((r) => r.json()),
fetch("/api/posts").then((r) => r.json()),
fetch("/api/stats").then((r) => r.json()),
]);
In an ideal environment where every network request succeeds, this code is efficient. However, the reality of web infrastructure is rarely ideal. If the statistics API encounters a 500 Internal Server Error, the entire Promise.all() block fails instantly. Even if the user data and post list were successfully retrieved and were ready to be displayed, they are effectively discarded.
From a user experience perspective, this is a catastrophic failure. Instead of seeing their profile and their content—with perhaps a small error message in the corner where the statistics should be—the user is often met with a blank screen or a generic "Something went wrong" message. The failure of a non-critical component (the statistics) has successfully "poisoned" the critical components (the user identity and core content). This lack of isolation between independent tasks forces the user to reload the entire page, hoping that the secondary API will function on the next attempt.
The Solution: A More Resilient Alternative
The development community recognized that the fail-fast behavior of Promise.all(), while useful for atomic operations where every step is vital, was often counterproductive for independent UI components. This led to the standardization of Promise.allSettled().
Unlike its predecessor, Promise.allSettled() does not care if a promise succeeds or fails in terms of its own resolution. It waits for every promise in the input array to "settle"—meaning it has either been fulfilled or rejected. Once all tasks have reached a final state, it returns an array of objects that describe the outcome of each operation.
Each object in the resulting array contains a status property, which is either "fulfilled" or "rejected". If fulfilled, the object contains a value representing the successful data; if rejected, it contains a reason explaining the failure. This structure allows developers to handle the results with far greater granularity:
const results = await Promise.allSettled([
fetch("/api/user").then((r) => r.json()),
fetch("/api/posts").then((r) => r.json()),
fetch("/api/stats").then((r) => r.json()),
]);
const [user, posts, stats] = results.map((r) =>
r.status === "fulfilled" ? r.value : null
);
if (stats === null)
console.warn("Unable to load statistics:", results[2].reason);
By adopting this pattern, the dashboard becomes significantly more robust. The application can now render the user information and the post list immediately, even if the statistics API is down. The user is provided with the data that is available, and the developer can implement a "graceful degradation" strategy, such as displaying a "Statistics temporarily unavailable" notice or a retry button specifically for that failed block. Furthermore, the error information is preserved, allowing for more accurate logging and debugging without disrupting the end-user’s workflow.
Applying It to Your Project
The decision to use Promise.allSettled() over Promise.all() should be guided by the relationship between the tasks being performed. The primary rule for developers is to evaluate independence: if the tasks are independent of each other and the application can provide value even with partial results, Promise.allSettled() is the superior choice.
This applies to a wide range of real-world scenarios beyond simple dashboards. For instance, an import utility processing a batch of files should not necessarily stop if one file is corrupted; it should process all valid files and report a summary of errors at the end. Similarly, a status monitoring screen checking the health of various microservices should report the status of each individual service, rather than failing entirely if one service is unreachable.
Another common use case is in communication features, such as an application sending notification emails to a list of recipients. If one email address is malformed and causes a rejection, it should not prevent the other valid recipients from receiving their messages. By using Promise.allSettled(), the system can ensure maximum delivery while identifying specific failures for later correction.
However, it is important to note that Promise.all() still has a vital place in software architecture. In scenarios where tasks are interdependent—such as a transaction where you must create an order record, deduct stock from inventory, and process a payment—the fail-fast behavior is exactly what is required. In these cases, if any step fails, the entire process must be halted to maintain data integrity.
FAQ
How is Promise.allSettled() different from Promise.all()?
The fundamental difference lies in how they handle rejection. Promise.all() will reject as soon as any of the input promises reject, effectively ignoring any successful results from other promises. In contrast, Promise.allSettled() will always wait for every promise to finish, regardless of the outcome, and provide a comprehensive report on which tasks succeeded and which failed.
Do the results keep the same order as the input promises?
Yes. One of the most reliable features of Promise.allSettled() is that the resulting array maintains the exact order of the input array. This is true regardless of which promise resolves first or how long each one takes to complete. This consistency allows developers to reliably map results back to their original requests using index-based assignment.
When should I still use Promise.all() instead of Promise.allSettled()?
You should continue to use Promise.all() when the operations are part of a single logical unit where "all must succeed or none should proceed." Examples include multi-step database transactions or complex calculations where the final result is dependent on every sub-calculation being accurate and present.
Which browsers and Node.js versions support Promise.allSettled()?
As an ES2020 feature, Promise.allSettled() enjoys broad support in modern environments. It is available in Google Chrome 76 and later, Firefox 71 and later, and Safari 13 and later. For server-side development, it is supported in Node.js version 12.9.0 and above. For projects that must support legacy browsers, such as Internet Explorer, developers should utilize a polyfill or a compatibility library like core-js.
References
The adoption of Promise.allSettled() reflects a broader trend in software engineering toward resilience and fault tolerance. As web applications become more distributed and rely on an increasing number of third-party services, the ability to handle partial failures is no longer just a "nice-to-have" feature—it is a requirement for professional-grade software.
By understanding the nuances between these different promise-handling methods, developers can write code that is not only more efficient but also more empathetic to the end-user. The shift from a blank screen to a partially functional, informative interface represents a significant step forward in the maturity of web applications. As this pattern becomes standard, the expectation for "graceful failure" continues to rise, pushing the industry toward more stable and reliable digital experiences.
