Lesson 4 of 30
The fix for a slow, sequential chain of requests isn't 'always fetch in parallel' — it's correctly telling apart requests that are genuinely independent from ones that have a real dependency.
11 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
Fetching a user by their email, then fetching that specific user's orders by the id the first call returned. Can these two requests be parallelized?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
The previous lesson's fix — firing independent requests together instead of waiting on each one in turn — only works when the requests are actually independent. The real skill isn't "wrap everything in a parallel call," it's correctly classifying each pair of requests as one of two cases:
Mistaking the second case for a fixable waterfall and trying to force it into a parallel call doesn't actually work — the second request would have to run with a value it doesn't have yet.
// Genuinely independent — parallelize
const [profile, notifications] = await Promise.all([
fetchProfile(userId),
fetchNotificationCount(userId),
]);
// Genuinely sequential — cannot parallelize, the second call needs the first's result
const user = await fetchUserByEmail(email);
const orders = await fetchOrdersForUser(user.id);
A common middle-ground case: even inside a sequential chain, there's often a genuinely independent piece that can still run alongside it.
// The dependent chain and an independent fetch, running together
const [user, appConfig] = await Promise.all([
fetchUserByEmail(email),
fetchGlobalConfig(), // doesn't depend on the user at all
]);
const orders = await fetchOrdersForUser(user.id); // still has to wait on `user`
fetchGlobalConfig doesn't need anything about the user, so it doesn't have to wait for fetchUserByEmail just because they happen to be needed on the same page. Only fetchOrdersForUser has a real reason to wait, because it needs user.id.
undefined, or the code doesn't compile/type-check because the value genuinely isn't available yet."Would you fetch these in parallel or sequentially?" for a scenario with a mix of dependent and independent requests is a real, common follow-up to any waterfall question, and correctly identifying which specific requests have a real dependency — rather than defaulting to either "always parallelize" or "always sequential" — is what separates surface-level pattern matching from actually reasoning about the data.