tezvyn:

How do you fetch from three APIs using Promise.all versus allSettled?

AI-drafted, machine-checkedSource: developer.mozilla.orgintermediate
How do you fetch from three APIs using Promise.all versus allSettled?
WHAT IT TESTS

Promise concurrency and failure isolation.

ANSWER OUTLINE

Promise.all parallelizes but rejects on first failure. allSettled returns every outcome with status, value, and reason.

RED FLAG

Wrapping each call in try-catch to imitate allSettled.

WHAT THIS TESTS: This question tests whether you understand the semantic differences between Promise concurrency methods, specifically the trade-off between fail-fast behavior and fault tolerance. Interviewers want to see that you know Promise.all is not just a parallelization utility but a strict combinator that rejects immediately on the first failure, discarding results from sibling promises. They also want to know you can choose Promise.allSettled when partial success is acceptable and every outcome matters, rather than inventing ad-hoc error-handling wrappers.

A GOOD ANSWER COVERS: First, explain that Promise.all takes an iterable of promises and returns a single promise that fulfills with an array of all values only if every input promise fulfills. Second, note the critical failure mode: if any input promise rejects, Promise.all immediately rejects with that reason, and the values from already-resolved promises are not surfaced to the caller. Third, introduce Promise.allSettled as the correct alternative when you need every result regardless of individual failures. Fourth, describe the return shape: an array of objects, each with a status property of either fulfilled or rejected, plus value or reason respectively, preserving order. Fifth, mention that allSettled never rejects; it always fulfills, so you only need a single then or await without a catch for the aggregate promise itself.

COMMON WRONG ANSWERS: A red flag is suggesting you keep Promise.all and wrap each fetch in a manual try-catch that resolves to null on failure. This reinvents allSettled poorly and obscures intent. Another red flag is claiming Promise.all returns whatever results it has at the moment of rejection; it does not. Some candidates suggest sequential awaits in a loop, which misses the parallelism requirement entirely. Finally, confusing allSettled with Promise.race or Promise.any is a signal of weak API familiarity.

LIKELY FOLLOW-UPS: The interviewer may ask how you would retry only the failed requests after using allSettled, or how to enforce a timeout across the aggregate operation. They might also ask about TypeScript typing for the results array, since allSettled produces a heterogeneous array of outcome objects. Another angle is memory or connection limits: how many parallel fetches are safe, and would you use a concurrency limiter instead of raw all or allSettled?

ONE CONCRETE EXAMPLE: Imagine fetching user profile, billing status, and notification preferences. With Promise.all, a billing API outage crashes the entire page even though profile and preferences are ready. With Promise.allSettled, you await all three, then iterate the results array. For each result, you check status. If fulfilled, you render the section. If rejected, you log the reason and show a graceful fallback UI for that card. The page loads every available module and isolates the outage.

Source: developer.mozilla.org

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.