JavaScript · Async JavaScript · Mid-Level · Best Practice
How do you run async operations in parallel vs sequentially with async/await? What are the trade-offs?
Short Interview Answer
Sequential: `await` one after another. Parallel: start promises first, then `await Promise.all`. Parallel is faster but uses more resources and fails differently.
Detailed Explanation
Sequential awaits are correct when each step depends on the previous. If independent, kicking off all promises before awaiting overlaps latency. `Promise.all` fails fast on first rejection; `allSettled` waits for all; `race`/`any` pick first settle/fulfill. Parallelism can overwhelm APIs — use pools/limits. In UI, parallel requests improve TTI but need cancellation (`AbortController`) on navigation. Always measure and respect rate limits.
Example
// sequential
const a = await fetchA();
const b = await fetchB();
// parallel
const [a2, b2] = await Promise.all([fetchA(), fetchB()]);Interview Tip
Call out failure semantics of `Promise.all` — interview favorite.
Common Mistake
Always awaiting in a `for` loop of independent requests, multiplying latency.