JavaScript·Intermediate·Coding·1 min read
How do you avoid accidental sequential requests?
Short interview answer
Create independent promises before awaiting them, then await them together with the combinator matching the failure semantics. Sequential await is correct only when later work depends on an earlier result or deliberate rate limiting is required.
Example
// Slow — second request waits for the first to finishconst user = await getUser(id);const posts = await getPosts(id);
// Fast — both start now, then we wait onceconst [user, posts] = await Promise.all([getUser(id), getPosts(id)]);Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.