← Back to the journal

The Problem With Using Promise.all() Everywhere

Running asynchronous tasks concurrently can make your JavaScript faster. It can also introduce problems that aren't immediately obvious.

On this page

The Problem With Using Promise.all() Everywhere

Reading position1 / 17
Editorial illustration for The Problem With Using Promise.all() Everywhere
AI-generated editorial illustration

One of the first performance improvements many JavaScript developers learn is replacing sequential await calls with Promise.all().

Instead of writing this:

const user = await getUser();
const orders = await getOrders();
const notifications = await getNotifications();

We write this:

const [user, orders, notifications] = await Promise.all([
  getUser(),
  getOrders(),
  getNotifications()
]);

Assuming these operations don't depend on one another, the second version is generally a better approach. We don't need to wait for one request to finish before starting another.

It's a simple improvement that can noticeably reduce loading times.

The trouble starts when we apply the same pattern to everything: database queries, background jobs, bulk uploads, email delivery, and hundreds of API requests.

What works beautifully for three independent requests doesn't necessarily work well for three thousand.

To understand why, let's look at five situations where Promise.all() might not be the right choice, and what we can use instead.

1. One failed request can ruin an otherwise successful operation

Imagine you're building an e-commerce dashboard that displays sales figures, recent orders, and customer reviews.

Each section retrieves its data from a different API endpoint.

async function loadDashboard() {
  const [sales, orders, reviews] = await Promise.all([
    getSales(),
    getOrders(),
    getReviews()
  ]);

  return { sales, orders, reviews };
}

Everything works until the customer reviews service experiences an outage.

Even if the sales and orders requests succeed, the entire Promise.all() expression rejects.

Article illustration
SVG source
<svg font-family="-apple-system-body, ui-sans-serif, -apple-system, system-ui, &quot;Segoe UI&quot;, Helvetica, &quot;Apple Color Emoji&quot;, Arial, sans-serif, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;" font-weight="400" data-d-component="svg" fill="currentColor" style="color:#1e293b" viewBox="0 0 340 174" width="100%" xmlns="http://www.w3.org/2000/svg"><rect x="8" y="12" width="145" height="35" rx="6" fill="#16a34a" fill-opacity=".08" stroke="#16a34a" stroke-opacity=".6"/><text x="18" y="26" font-size="11" font-weight="600" fill="currentColor">Sales API</text><text x="18" y="39" font-size="10" fill="#16a34a">Success</text><path d="M153 29.5 H175 V75 H193" fill="none" stroke="currentColor" opacity=".35"/><rect x="8" y="58" width="145" height="35" rx="6" fill="#16a34a" fill-opacity=".08" stroke="#16a34a" stroke-opacity=".6"/><text x="18" y="72" font-size="11" font-weight="600" fill="currentColor">Orders API</text><text x="18" y="85" font-size="10" fill="#16a34a">Success</text><path d="M153 75.5 H175 V75 H193" fill="none" stroke="currentColor" opacity=".35"/><rect x="8" y="104" width="145" height="35" rx="6" fill="#dc2626" fill-opacity=".08" stroke="#dc2626" stroke-opacity=".6"/><text x="18" y="118" font-size="11" font-weight="600" fill="currentColor">Reviews API</text><text x="18" y="131" font-size="10" fill="#dc2626">Failed</text><path d="M153 121.5 H175 V75 H193" fill="none" stroke="currentColor" opacity=".35"/><rect x="193" y="53" width="139" height="45" rx="6" fill="#dc2626" fill-opacity=".08" stroke="#dc2626" stroke-opacity=".65"/><text x="262" y="71" text-anchor="middle" font-size="12" font-weight="600" fill="currentColor">Promise.all()</text><text x="262" y="85" text-anchor="middle" font-size="11" fill="#dc2626">Rejected</text><text x="170" y="161" text-anchor="middle" font-size="11" fill="currentColor">Two successful results, but no combined result.</text></svg>
Download SVG

This is the fail-fast behaviour of Promise.all(). It rejects when one of its input promises rejects. 

But think about it from the user's perspective.

Should an unavailable customer reviews service prevent someone from viewing their sales figures?

Probably not.

A better approach: Promise.allSettled()

async function loadDashboard() {
  const [sales, orders, reviews] =
    await Promise.allSettled([
      getSales(),
      getOrders(),
      getReviews()
    ]);

  return {
    sales: sales.status === "fulfilled"
      ? sales.value
      : null,

    orders: orders.status === "fulfilled"
      ? orders.value
      : null,

    reviews: reviews.status === "fulfilled"
      ? reviews.value
      : null
  };
}

Unlike Promise.all(), Promise.allSettled() waits for every input promise to finish and reports its individual outcome. 

Each result has one of two structures:

{
  status: "fulfilled",
  value: data
}

Or:

{
  status: "rejected",
  reason: error
}

We can now display the sales and orders sections normally while showing an error message in the reviews section.

In a production dashboard, we would also retain or log the rejection reasons so that service failures remain observable.

This technique is particularly useful for dashboards, bulk file uploads, notification delivery, and operations where partial success is acceptable.

The important question isn't whether every request succeeded. It's whether the application can still provide value when some of them fail.

2. You might be sending more requests than your server can handle

Consider a backend application that needs to retrieve information for 1,000 products.

A straightforward implementation might look like this:

const products = await Promise.all(
  productIds.map(id => fetchProduct(id))
);

It looks efficient, and for ten products, it probably is.

But for 1,000 products, the behaviour is quite different.

The map() callback invokes fetchProduct() for every product ID without waiting for previous requests to finish.

Depending on the underlying implementation, this can lead to:

  • API rate limiting and HTTP 429 responses.

  • Exhausted database connection pools.

  • Increased memory consumption.

  • Overloaded downstream services.

  • Increased request latency.

  • Resource contention with other users.

The actual number of simultaneous network connections depends on the runtime and transport. However, your application has still attempted to initiate all 1,000 operations.

Promise.all() doesn't provide a concurrency limit.

A better approach: Controlled concurrency

One useful library for this is p-limit.

npm install p-limit

Instead of starting every request immediately, we can limit the number of active operations.

import pLimit from "p-limit";

const limit = pLimit(10);

const products = await Promise.all(
  productIds.map(id =>
    limit(() => fetchProduct(id))
  )
);

Now, at most ten of the scheduled product-fetching operations will be active through this limiter at any given time.

As one finishes, another can begin.

Unlimited vs. controlled concurrency

Controlled concurrency keeps the workload moving without initiating everything at once.

Article illustration
SVG source
<svg font-family="-apple-system-body, ui-sans-serif, -apple-system, system-ui, &quot;Segoe UI&quot;, Helvetica, &quot;Apple Color Emoji&quot;, Arial, sans-serif, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;" font-weight="400" data-d-component="svg" fill="currentColor" style="color:#1e293b" viewBox="0 0 340 207" width="100%" xmlns="http://www.w3.org/2000/svg"><text x="10" y="15" font-size="12" font-weight="600" fill="currentColor">Without a concurrency limit</text><rect x="10" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="30" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="50" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="70" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="90" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="110" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="130" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="150" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="170" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="190" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="210" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="230" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="250" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="270" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="290" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="310" y="27" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="10" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="30" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="50" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="70" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="90" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="110" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="130" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="150" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="170" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="190" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="210" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="230" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="250" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="270" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="290" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="310" y="46" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="10" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="30" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="50" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="70" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="90" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="110" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="130" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="150" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="170" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="190" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="210" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="230" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="250" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="270" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="290" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><rect x="310" y="65" width="16" height="15" rx="3" fill="#d97706" fill-opacity=".8"/><text x="10" y="98" font-size="10" fill="currentColor" opacity=".7">All 48 illustrated tasks initiated together</text><path d="M10 111 H330" stroke="currentColor" opacity=".15"/><text x="10" y="130" font-size="12" font-weight="600" fill="currentColor">With a concurrency limit of 10</text><rect x="10" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="30" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="50" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="70" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="90" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="110" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="130" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="150" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="170" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="190" y="142" width="16" height="15" rx="3" fill="#16a34a" fill-opacity="0.85" stroke="#16a34a" stroke-opacity=".4"/><rect x="210" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="230" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="250" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="270" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="290" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="310" y="142" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="10" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="30" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="50" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="70" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="90" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="110" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="130" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="150" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="170" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="190" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="210" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="230" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="250" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="270" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="290" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="310" y="161" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="10" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="30" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="50" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="70" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="90" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="110" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="130" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="150" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="170" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="190" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="210" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="230" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="250" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="270" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="290" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="310" y="180" width="16" height="15" rx="3" fill="#888888" fill-opacity="0.15" stroke="#888888" stroke-opacity=".4"/><rect x="10" y="195" width="10" height="10" rx="2" fill="#16a34a"/><text x="25" y="204" font-size="10" fill="currentColor">Active</text><rect x="85" y="195" width="10" height="10" rx="2" fill="#888888" fill-opacity=".2"/><text x="100" y="204" font-size="10" fill="currentColor">Waiting</text></svg>
Download SVG

Notice that we're still using Promise.all().

The difference is that we've separated the responsibility of managing concurrency from the responsibility of collecting results.

The p-limit library is specifically designed for limiting concurrent executions of asynchronous functions. 

GitHub

What if you don't want another dependency?

A simple alternative is batch processing.

async function fetchProducts(ids, batchSize = 10) {
  const results = [];

  for (let i = 0; i < ids.length; i += batchSize) {
    const batch = ids.slice(i, i + batchSize);

    const products = await Promise.all(
      batch.map(id => fetchProduct(id))
    );

    results.push(...products);
  }

  return results;
}

This works, although it has a limitation.

If nine requests finish quickly but the tenth is slow, the next batch cannot begin until that last request completes.

A concurrency limiter can keep available execution slots occupied without waiting for an entire batch to finish.

Also, concurrency limiting is not the same as rate limiting. Ten concurrent requests could still exceed an API's limit of 100 requests per minute if the requests finish sufficiently quickly.

Choose the concurrency limit based on your actual API restrictions, database capacity, and performance measurements. Ten is simply an illustrative starting point.

3. Rejecting a promise doesn't cancel the remaining operations

This is one of the more misunderstood aspects of Promise.all().

Consider the following example, which you can try in a modern JavaScript console.

function task(name, delay, shouldFail = false) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(`${name} finished`);

      if (shouldFail) {
        reject(new Error(`${name} failed`));
      } else {
        resolve(name);
      }
    }, delay);
  });
}

try {
  await Promise.all([
    task("Task A", 1000),
    task("Task B", 500, true),
    task("Task C", 3000)
  ]);
} catch (error) {
  console.log(error.message);
}

You should see output similar to this:

Task B finished
Task B failed
Task A finished
Task C finished

Promise.all() has already rejected after approximately 500 milliseconds.

Yet Task A and Task C continue running.

Article illustration
SVG source
<svg font-family="-apple-system-body, ui-sans-serif, -apple-system, system-ui, &quot;Segoe UI&quot;, Helvetica, &quot;Apple Color Emoji&quot;, Arial, sans-serif, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;" font-weight="400" data-d-component="svg" fill="currentColor" style="color:#1e293b" viewBox="0 0 340 173" width="100%" xmlns="http://www.w3.org/2000/svg"><path d="M72 20 V143" stroke="currentColor" stroke-dasharray="3 4" opacity=".18"/><text x="72" y="158" font-size="10" fill="currentColor" text-anchor="middle">0s</text><path d="M154 20 V143" stroke="currentColor" stroke-dasharray="3 4" opacity=".18"/><text x="154" y="158" font-size="10" fill="currentColor" text-anchor="middle">1s</text><path d="M236 20 V143" stroke="currentColor" stroke-dasharray="3 4" opacity=".18"/><text x="236" y="158" font-size="10" fill="currentColor" text-anchor="middle">2s</text><path d="M318 20 V143" stroke="currentColor" stroke-dasharray="3 4" opacity=".18"/><text x="318" y="158" font-size="10" fill="currentColor" text-anchor="middle">3s</text><text x="5" y="38" font-size="11" fill="currentColor">Task A</text><rect x="72" y="25" width="82" height="18" rx="4" fill="#16a34a" fill-opacity=".7"/><text x="5" y="73" font-size="11" fill="currentColor">Task B</text><rect x="72" y="60" width="41" height="18" rx="4" fill="#dc2626" fill-opacity=".8"/><text x="5" y="108" font-size="11" fill="currentColor">Task C</text><rect x="72" y="95" width="246" height="18" rx="4" fill="#16a34a" fill-opacity=".7"/><path d="M113 12 V127" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="4 3"/><text x="119" y="10" font-size="10" fill="#dc2626">Promise.all() rejects</text><text x="215" y="131" font-size="10" fill="currentColor" text-anchor="middle">Other tasks continue running</text></svg>
Download SVG

What continues after Promise.all() rejects?

Illustrative execution timeline based on the example's timer durations.

A JavaScript promise represents the eventual outcome of an operation. Rejecting the combined promise doesn't inherently stop its underlying work. 

This becomes more concerning when the operations have side effects.

Imagine this checkout implementation:

await Promise.all([
  chargeCustomer(),
  deductInventory(),
  sendConfirmationEmail()
]);

If charging the customer fails, the inventory operation and confirmation email may still complete.

You could end up reducing your inventory and sending a customer a confirmation email for a payment that never succeeded.

A better approach: Explicit cancellation where supported

For network requests, we can use AbortController.

async function fetchAll(urls) {
  const controller = new AbortController();

  try {
    return await Promise.all(
      urls.map(async url => {
        const response = await fetch(url, {
          signal: controller.signal
        });

        if (!response.ok) {
          throw new Error(`HTTP ${response.status}`);
        }

        return response.json();
      })
    );
  } catch (error) {
    controller.abort();
    throw error;
  }
}

All requests share the same abort signal.

If one request fails, we signal the remaining fetch operations to stop. This can also cancel response body consumption that is still in progress. 

However, cancellation is not the same as rolling back an operation.

A request that has already reached a server might have triggered a database update, payment, or another side effect.

For operations involving payments, inventory, or other critical state changes, you may need database transactions, idempotency keys, compensating actions, or a properly coordinated workflow.

Simply wrapping everything in Promise.all() doesn't make a collection of operations atomic.

4. Not every asynchronous operation should run concurrently

There's a tendency to associate sequential await calls with poorly optimised JavaScript.

But sometimes, sequential execution is exactly what we need.

Consider a function that imports customer orders into a database.

async function importOrder(data) {
  const customer = await createCustomer(data.customer);

  const order = await createOrder({
    customerId: customer.id,
    items: data.items
  });

  await generateInvoice(order.id);

  return order;
}

Each operation depends on the result of the previous one.

We need the customer ID before creating the order, and we need the order ID before generating the invoice.

Trying to force concurrency into this workflow would make the implementation unnecessarily complicated.

However, we can still look for opportunities to run independent operations concurrently.

Suppose creating an order requires customer information, product information, and shipping rates.

async function processOrder(customerId, productIds) {
  const [customer, products, shipping] =
    await Promise.all([
      getCustomer(customerId),
      getProducts(productIds),
      getShippingRates()
    ]);

  const order = await createOrder({
    customer,
    products,
    shipping
  });

  await generateInvoice(order.id);

  return order;
}

We've combined concurrent and sequential execution within the same function.

Article illustration
SVG source
<svg font-family="-apple-system-body, ui-sans-serif, -apple-system, system-ui, &quot;Segoe UI&quot;, Helvetica, &quot;Apple Color Emoji&quot;, Arial, sans-serif, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;" font-weight="400" data-d-component="svg" fill="currentColor" style="color:#1e293b" viewBox="0 0 340 231" width="100%" xmlns="http://www.w3.org/2000/svg"><rect x="5" y="10" width="104" height="36" rx="6" fill="#3b82f6" fill-opacity=".08" stroke="#3b82f6" stroke-opacity=".6"/><text x="57" y="32" text-anchor="middle" font-size="11" fill="currentColor">Get customer</text><path d="M57 46 V67 H170 V82" stroke="currentColor" opacity=".4" fill="none"/><rect x="118" y="10" width="104" height="36" rx="6" fill="#3b82f6" fill-opacity=".08" stroke="#3b82f6" stroke-opacity=".6"/><text x="170" y="32" text-anchor="middle" font-size="11" fill="currentColor">Get products</text><path d="M170 46 V67 H170 V82" stroke="currentColor" opacity=".4" fill="none"/><rect x="231" y="10" width="104" height="36" rx="6" fill="#3b82f6" fill-opacity=".08" stroke="#3b82f6" stroke-opacity=".6"/><text x="283" y="32" text-anchor="middle" font-size="11" fill="currentColor">Shipping rates</text><path d="M283 46 V67 H170 V82" stroke="currentColor" opacity=".4" fill="none"/><rect x="87" y="82" width="166" height="35" rx="6" fill="#3b82f6" fill-opacity=".08" stroke="#3b82f6" stroke-opacity=".6"/><text x="170" y="104" font-size="12" font-weight="600" text-anchor="middle" fill="currentColor">Promise.all()</text><path d="M170 117 V139 M165 134 L170 139 L175 134" stroke="currentColor" opacity=".5" fill="none"/><rect x="87" y="140" width="166" height="32" rx="6" fill="#16a34a" fill-opacity=".08" stroke="#16a34a" stroke-opacity=".6"/><text x="170" y="160" font-size="12" text-anchor="middle" fill="currentColor">Create order</text><path d="M170 172 V190 M165 185 L170 190 L175 185" stroke="currentColor" opacity=".5" fill="none"/><rect x="87" y="191" width="166" height="32" rx="6" fill="#16a34a" fill-opacity=".08" stroke="#16a34a" stroke-opacity=".6"/><text x="170" y="211" font-size="12" text-anchor="middle" fill="currentColor">Generate invoice</text><text x="5" y="100" font-size="10" fill="#3b82f6">Concurrent</text><text x="5" y="159" font-size="10" fill="#16a34a">Sequential</text></svg>
Download SVG

Run independent operations concurrently while preserving the order of dependent operations.

This is often how asynchronous workflows should be structured.

Instead of asking how many await statements we can eliminate, we should identify which operations actually depend on one another.

A well-placed sequential await isn't a performance mistake. Sometimes, it's a business requirement.

5. Sometimes, you don't need every result

Imagine you're building a service that retrieves data from three equivalent mirror servers.

You don't need three copies of the same data. You just need one successful response.

Using Promise.all() would mean waiting for the slowest server, assuming all three requests succeed.

const results = await Promise.all([
  fetchFromServerA(),
  fetchFromServerB(),
  fetchFromServerC()
]);

return results[0];

We're doing unnecessary waiting.

JavaScript provides two alternatives for situations like this, although they solve slightly different problems.

Use Promise.any() when you need the first successful result

const result = await Promise.any([
  fetchFromServerA(),
  fetchFromServerB(),
  fetchFromServerC()
]);

If Server A fails, but Server B succeeds, we still get a result.

Promise.any() only rejects when all input promises reject. In that situation, it produces an AggregateError. 

This is useful when working with redundant services or equivalent data sources.

One detail to be careful about is that fetch() doesn't automatically reject when a server returns an HTTP error status such as 404 or 500.

If you're using Promise.any() with HTTP requests, make sure unsuccessful HTTP responses are treated as failures.

async function fetchJSON(url) {
  const response = await fetch(url);

  if (!response.ok) {
    throw new Error(`HTTP ${response.status}`);
  }

  return response.json();
}

const data = await Promise.any([
  fetchJSON("https://api.example.com/data"),
  fetchJSON("https://backup.example.com/data")
]);

Without that check, an HTTP 500 response could incorrectly become your winning result. 

Also, the remaining requests aren't automatically cancelled once you receive a successful result.

Sending redundant requests increases traffic, so this approach should be used deliberately rather than as a default for every API call.

Use Promise.race() when you need the first outcome

Promise.race() behaves differently.

It settles as soon as one of its input promises settles, whether that outcome is a success or a failure.

A common example is implementing a timeout.

function timeout(ms) {
  return new Promise((_, reject) => {
    setTimeout(() => {
      reject(new Error("Operation timed out"));
    }, ms);
  });
}

const data = await Promise.race([
  fetchJSON("/api/products"),
  timeout(5000)
]);

If the request takes too long, the combined promise rejects.

However, remember what we discussed earlier: rejecting a promise doesn't automatically cancel the underlying request. The timeout timer also remains scheduled if the request finishes first, unless we explicitly clear it.

For modern environments supporting AbortSignal.timeout(), there's a cleaner solution when working with fetch().

async function fetchProducts() {
  const response = await fetch("/api/products", {
    signal: AbortSignal.timeout(5000)
  });

  if (!response.ok) {
    throw new Error(`HTTP ${response.status}`);
  }

  return response.json();
}

Now we're not simply giving up on waiting. We're using the Fetch API's cancellation mechanism to abort the request when the timeout occurs. 

MDN

Understanding the four JavaScript promise methods

These methods look similar, but their behaviour is quite different.

Consider three asynchronous operations with the following outcomes:

JavaScript Promise Comparison. Comparing the execution timelines of Promise.all,
    Promise.allSettled, Promise.any and Promise.race.
Comparing the execution timelines of Promise.all, Promise.allSettled, Promise.any and Promise.race.
SVG source
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 520" width="640" height="520" role="img" aria-labelledby="title description">

  <title id="title">JavaScript Promise Comparison</title>
  <desc id="description">
    Comparing the execution timelines of Promise.all,
    Promise.allSettled, Promise.any and Promise.race.
  </desc>

  <style>
    text {
      font-family: Arial, Helvetica, sans-serif;
    }

    .task-label {
      font-size: 19px;
      font-weight: 500;
      fill: #1e293b;
    }

    .axis-label {
      font-size: 17px;
      fill: #1e293b;
      text-anchor: middle;
    }

    .grid-line {
      stroke: #cbd5e1;
      stroke-width: 1;
      stroke-dasharray: 6 5;
    }

    .method-label {
      font-size: 13px;
      font-weight: 500;
      fill: #1e293b;
    }

    .description {
      font-size: 11px;
      fill: #475569;
    }

    .status {
      font-size: 12px;
      text-anchor: end;
    }

    .success {
      fill: #15803d;
    }

    .failure {
      fill: #b91c1c;
    }

    .progress-track {
      fill: #e2e8f0;
    }
  </style>

  <!-- Background -->
  <rect width="640" height="520" rx="10" fill="#ffffff"></rect>

  <!-- Timeline grid -->
  <g class="grid-line">
    <line x1="132" y1="24" x2="132" y2="224"></line>
    <line x1="218" y1="24" x2="218" y2="224"></line>
    <line x1="304" y1="24" x2="304" y2="224"></line>
    <line x1="390" y1="24" x2="390" y2="224"></line>
    <line x1="476" y1="24" x2="476" y2="224"></line>
    <line x1="562" y1="24" x2="562" y2="224"></line>
  </g>

  <!-- Task A -->
  <text x="24" y="70" class="task-label">Task A</text>
  <rect x="132" y="46" width="172" height="34" rx="7" fill="#15803d"></rect>
  <text x="313" y="69" font-size="17" class="success">Success</text>

  <!-- Task B -->
  <text x="24" y="134" class="task-label">Task B</text>
  <rect x="132" y="110" width="86" height="34" rx="7" fill="#b91c1c"></rect>
  <text x="227" y="133" font-size="17" class="failure">Failed</text>

  <!-- Task C -->
  <text x="24" y="198" class="task-label">Task C</text>
  <rect x="132" y="174" width="430" height="34" rx="7" fill="#15803d"></rect>
  <text x="549" y="197" font-size="17" text-anchor="end" fill="#ffffff">Success</text>

  <!-- Timeline labels -->
  <g class="axis-label">
    <text x="132" y="251">0s</text>
    <text x="218" y="251">1s</text>
    <text x="304" y="251">2s</text>
    <text x="390" y="251">3s</text>
    <text x="476" y="251">4s</text>
    <text x="562" y="251">5s</text>
  </g>

  <!-- Promise.all() -->
  <g>
    <text x="16" y="294" class="method-label">
      Promise.all()
    </text>
    <text x="624" y="294" class="status failure">
      Rejected · 1s
    </text>

    <rect x="16" y="304" width="608" height="7" rx="3.5" class="progress-track"></rect>
    <rect x="16" y="304" width="121.6" height="7" rx="3.5" class="failure"></rect>

    <text x="16" y="327" class="description">
      Rejects when Task B fails.
    </text>
  </g>

  <!-- Promise.allSettled() -->
  <g>
    <text x="16" y="352" class="method-label">
      Promise.allSettled()
    </text>
    <text x="624" y="352" class="status success">
      Fulfilled · 5s
    </text>

    <rect x="16" y="362" width="608" height="7" rx="3.5" class="progress-track"></rect>
    <rect x="16" y="362" width="608" height="7" rx="3.5" class="success"></rect>

    <text x="16" y="385" class="description">
      Returns all three individual outcomes.
    </text>
  </g>

  <!-- Promise.any() -->
  <g>
    <text x="16" y="410" class="method-label">
      Promise.any()
    </text>
    <text x="624" y="410" class="status success">
      Fulfilled · 2s
    </text>

    <rect x="16" y="420" width="608" height="7" rx="3.5" class="progress-track"></rect>
    <rect x="16" y="420" width="243.2" height="7" rx="3.5" class="success"></rect>

    <text x="16" y="443" class="description">
      Returns Task A's successful result.
    </text>
  </g>

  <!-- Promise.race() -->
  <g>
    <text x="16" y="468" class="method-label">
      Promise.race()
    </text>
    <text x="624" y="468" class="status failure">
      Rejected · 1s
    </text>

    <rect x="16" y="478" width="608" height="7" rx="3.5" class="progress-track"></rect>
    <rect x="16" y="478" width="121.6" height="7" rx="3.5" class="failure"></rect>

    <text x="16" y="501" class="description">
      Rejects because Task B settles first.
    </text>
  </g>

</svg>
Download SVG

The choice of promise method changes when your application receives a result and how it responds to failure. It does not, by itself, change which underlying operations continue running.

A quick reference

MethodWhen it completesBest use case
Promise.all()All succeed or one rejectsEvery result is required
Promise.allSettled()All inputs settlePartial success is acceptable
Promise.any()First success or all rejectEquivalent fallback services
Promise.race()First success or failureCompeting outcomes
p-limitControls active operationsLarge asynchronous workloads
Sequential awaitOne operation at a timeDependent operations
AbortControllerSignals cancellationStopping supported operations

When should you actually use Promise.all()?

Despite the title of this article, Promise.all() remains one of the most useful tools in asynchronous JavaScript.

If I'm loading an application's initial configuration, permissions, and feature flags, and the application cannot function without all three, I would happily use it.

const [config, permissions, flags] =
  await Promise.all([
    getConfig(),
    getPermissions(),
    getFeatureFlags()
  ]);

It's concise, readable, and appropriate for the problem.

Before using it, though, consider these five questions:

  1. Are the operations independent?

  2. Do I need every result to succeed?

  3. Is the number of concurrent operations manageable?

  4. What should happen to the remaining operations if one fails?

  5. Could any of these operations leave behind unwanted side effects?

If you can answer these questions, you'll have a much better understanding of whether Promise.all() belongs in that particular piece of code.

Final thoughts

It's easy to look at ten sequential await statements and assume that wrapping them in Promise.all() is an optimisation.

Sometimes it is.

Other times, we've simply replaced a predictable workflow with ten concurrent opportunities for something to go wrong.

The more interesting part of asynchronous programming isn't learning how to execute everything concurrently. It's understanding what should happen when operations fail, take too long, depend on each other, or compete for limited resources.

You don't always need more concurrency.

Sometimes, you just need better control over it.

THE CONVERSATION

Comments

Add your perspective ↓

Questions, useful examples and different approaches are welcome. Keep the discussion thoughtful and on topic.

Loading comments…

    Add your perspective

    All comments are reviewed before publication. Your name and comment will be public after approval; your email stays private and is used for account access or moderation, not a mailing list.

    Checking sign-in…