Lesson 17 of 30
An autocomplete box looks like a small UI detail, but as a system design prompt it packs three real problems into one: not firing a request per keystroke, not letting a slow earlier response overwrite a faster later one, and not refetching what you already have.
13 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
A user types 'rea', then quickly types 'reac' before the first request resolves. The 'rea' response arrives after the 'reac' response and is rendered last, overwriting the newer, more relevant results. What kind of problem is this?
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 prompt: "Design the frontend architecture for a search-as-you-type autocomplete box" — the user types, and matching suggestions appear within a keystroke or two, without the UI feeling laggy or showing the wrong results. It looks like a small feature, but a strong answer has to name three separate problems and solve each one:
Say a user types "rea", pauses just long enough to fire a debounced request, then keeps typing "reac" before the first request has resolved. Two requests are now in flight: one for "rea", one for "reac". Networks don't guarantee response order — it's entirely possible for the "rea" request, despite being sent first, to resolve after the "reac" request because of ordinary network jitter.
If the response handler naively does "whatever comes back, render it," the UI can show results for "rea" after the user has already typed "reac" and is looking at newer, faster results — an older, less relevant response silently overwriting a newer, more relevant one. This is a real, common bug class, not a hypothetical edge case: it happens whenever multiple requests for the same evolving input can be in flight at once.
The fix is tracking which request is the current one and discarding any response that isn't it — commonly done by stamping each outgoing request with an incrementing id or the query string itself, then checking on response arrival: "is this response for the query that's still active?" If not, the response is thrown away, even though the network call completed successfully.
A small local cache, keyed by the exact query string, closes the third gap: if a user types "reac", backspaces to "rea", then retypes "reac", the second "reac" request doesn't need to hit the network again if the first result set is still in the cache. This also happens to make the stale-response problem rarer in practice, since a cache hit resolves synchronously and never races anything.
"Design an autocomplete box" is asked specifically to see whether a candidate reaches past the obvious debounce answer to the request-ordering bug underneath it — that's the detail that separates a surface-level answer from one that shows real production experience with this exact component.