City Fetcher API
Problem statement
Implement getAllCities(country). First fetch the states for a country, then fetch the cities for each state, and return one flat list of all cities.
This is a real-world async pattern: one request gives you IDs, then several follow-up requests can run in parallel.
How to approach City Fetcher API
The strategy an interviewer expects you to reach for.
City fetcher is nested async IO: countries → states → cities. The trap is uncontrolled parallelism and poorly merged results. Naive move Nest callbacks or fire unbounded getCities calls without coordination. Where it breaks Too many parallel requests, unclear ordering, and mutations of shared arrays while awaits interleave. The fix Fetch states for a country, then either sequence city fetches or bound parallel Promise.all over states, and concatenate results intentionally after awaits complete. Remember: Choose explicit serial vs bounded parallel — never accidental racey pushes. Say this in the interview: I'd fetch states first, then load cities per state with an explicit Promise.all or serial loop, and only merge arrays after those promises resolve.
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Runnable editor with the hidden test suite
- Progressive hints that unlock as you get stuck
- Senior-level reference solution with a line-by-line walkthrough
Already a member? Log in to open the workspace.