Skip to the page

async/await exactly · mid

Sequential vs parallel async work

Awaiting inside a loop runs tasks one after another (total time = the sum), while starting them all and awaiting Promise.all runs them concurrently (total time ≈ the slowest); choose sequential only when each step needs the previous result or you must limit load.

The notes

What you must know

  • Waterfall: const a = await getA(); const b = await getB(); wastes time when b doesn't need a. Start both, then await: const [a, b] = await Promise.all([getA(), getB()]).
  • for...of with await is sequential. items.map(async ...) plus Promise.all is concurrent. A reduce over a promise chain is sequential without async/await (Flipkart asked this in 2025).
  • Unlimited concurrency (1,000 requests at once) overloads servers and hits the browser's per-host connection limit; use a pool.
  • If you start a promise early and await it later, something that throws in between can leave it unhandled. Attach handlers or use Promise.all.
  • for await...of over an array of promises awaits them in order, but they were already running at the same time.

The red pen

Common traps: mistake → fix

  • Mistake: Promise.all runs things one by one

    Fix: concurrently; only the result order is preserved.

  • Mistake: items.map(async ...) is sequential

    Fix: map starts every call immediately.

  • Mistake: await in a loop is always wrong

    Fix: it is right when steps depend on each other or you need rate limiting.

Easy to hard

Questions interviewers ask, easy to hard

  1. How long does this loop with await take, and how do you speed it up? (Swiggy, Dec 2024)
  2. Run an array of async functions in parallel, then in sequence without async/await. (Flipkart, 2025)
  3. When is sequential the correct choice?
  4. Start 100 requests but keep at most 5 running at a time.

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview