Classic case studies · senior
Case study: autocomplete / typeahead
A strong autocomplete design debounces input, cancels stale requests and ignores late responses, caches results by normalised query, follows the ARIA combobox pattern with focus kept on the input, handles IME typing, and exposes a small reusable API.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Component API: value/onChange (controlled) or defaultValue; source(query, { signal }) for async data; minChars; debounceMs; renderOption; onSelect; getOptionLabel; a way to pass static options.
- Typing: debounce about 200–300 ms; skip queries shorter than minChars; abort the previous request with AbortController AND check that a response belongs to the latest query (a cached or non-abortable promise can still arrive late).
- Cache: Map or LRU keyed by trimmed, lower-cased query with a TTL; reuse a shorter query's results only when the server returned the complete set for that prefix.
- Results: cap to about 10, highlight the match by splitting text into parts (never innerHTML), show loading, 'No results' and an error with Retry.
- Accessibility (APG): input role=combobox, aria-expanded, aria-controls → listbox, aria-activedescendant → active option, options with aria-selected; Down/Up move, Enter selects, Escape closes; DOM focus stays on the input; a polite live region announces the result count.
- IME: don't search between compositionstart and compositionend (Hindi, Japanese, Chinese input).
- Popup: render in the top layer (Popover API is Baseline 2025) or a portal so overflow: hidden parents don't clip it; reposition on scroll/resize (or CSS anchor positioning where supported); handle the mobile keyboard covering the list.
- Server side and metrics: a prefix index or search service, popular prefixes cached at the edge, recent searches stored locally; measure keystroke-to-results time at p75 and suggestion click-through rate.
The red pen
Common traps: mistake → fix
Mistake: Send a request on every keystroke
Fix: wasted calls and rate limits.
Mistake: Show whatever response arrives last
Fix: the 'lap' results can overwrite 'laptop'.
Mistake: Mouse-only list
Fix: fails keyboard and screen-reader users.
Mistake: Highlight with innerHTML and the raw query
Fix: XSS and broken regex characters.
Easy to hard
Questions interviewers ask, easy to hard
- Design a reusable autocomplete used for search, user pickers and address lookup.
- The user types quickly. When do requests go out, and how do you avoid stale results?
- What can a cached result for a shorter query tell you?
- Make it accessible. Where is focus?
- The popup is inside a dialog with overflow: hidden. Which layer closes on Escape?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.