How to perform multiple asynchronous requests starting one after another
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If multiple asynchronous requests must start one after another, you do not want parallel execution. You want sequencing. In JavaScript, the clearest solution is usually a for...of loop with await, because each request begins only after the previous one has completed.
Sequential Requests with async and await
Here is the most direct pattern:
This starts request b only after request a is fully resolved, and request c only after b finishes.
That is the right behavior when:
- order matters
- later requests depend on earlier results
- you must avoid overlapping load on a downstream service
Use Prior Results in the Next Request
Sequential execution becomes especially important when each step depends on the last step’s output.
This is not just a style choice. These requests cannot run correctly in parallel because the later URLs are not even known yet.
Promise Chaining Works Too
Before async and await, the usual solution was promise chaining.
This still works, but async and await is usually easier to read and maintain for multi-step flows.
Process an Array Sequentially
If you already have an array of tasks, loop through them rather than using Promise.all.
Do not use Promise.all here if the requirement is "one after another," because Promise.all starts everything immediately.
Avoid forEach with async
This is a common mistake:
forEach does not wait for each callback the way people often expect. The requests begin independently, so the code is not truly sequential.
If you need real sequencing, use for...of.
Add Error Handling and Timeouts
Sequential flows still need operational safeguards. One slow or broken request can stall the whole chain.
Then use it in the sequential loop so each step has a bounded wait time.
Common Pitfalls
The most common mistake is using Promise.all or forEach when the requirement is actually sequential execution. Another is forgetting that one failed request can stop the whole chain unless you handle errors deliberately. Developers also sequence requests by habit when they could safely run them in parallel, which hurts performance for no reason. The right question is not "can I await in a loop" but "does the problem require sequence or concurrency."
Summary
- Use
for...ofwithawaitwhen requests must start one after another. - Use sequential flow when later requests depend on earlier results or when order matters.
- Promise chaining also works, but
asyncandawaitis usually clearer. - Avoid
forEachfor sequencing asynchronous work. - Add timeouts and error handling so one bad request does not stall the entire workflow silently.
Related reading
- How to pick an event listener that will let me wait until async.times is finished to run a function
- How to play sounds asynchronuously, but themselves in a queue?
- How to preserve HttpContext in Web API async task
- How to process GuzzleHTTP async requests without blocking?
- How to populate select options from an Api call in React js on page load
- How to post query parameters with Axios?
- How to promisify correctly JSON.parse method with bluebird
- How to properly fire a callback after an animation and ajax calls have been successfully completed?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.