Design an Autocomplete / Search UI
Problem statement
Design a typeahead search bar with debouncing, client-side caching, full keyboard navigation, recent searches, and proper ARIA combobox patterns.
Asked In
Key Challenges
- ·Debounced API calls without excessive network requests or jank
- ·Keyboard navigation (arrows, enter, escape, tab) with proper focus management
- ·Highlighting matched search terms in results
- ·Caching and deduplication of results to avoid duplicate fetches
- ·Full ARIA combobox accessibility (screen readers, live regions, activedescendant)
2-Minute Answer — High-Level TL;DR
Read this before your interview
HLD Interview Focus
Treat autocomplete as a request lifecycle. After a short debounce, check a query-keyed cache, request suggestions, and show explicit loading, empty, and error states. Abort obsolete requests and guard result updates with the active query or request ID: cancellation alone is not a correctness guarantee. Keep input focus while arrow keys change the active listbox option, Enter selects, and Escape closes. Clarify minimum query length, cache freshness, free-text submission, and keyboard behavior before styling.
My Approach: Building the Solution
How to think about this problem
Trace input → debounce → cache lookup → request → active-request check → results. Define the combobox interaction contract alongside the request state machine.
Why This Approach?
Debounce limits traffic but adds delay; caching reduces latency but needs a freshness policy. Neither replaces a guard against old responses overwriting a newer query.
Autocomplete is like a librarian who starts walking to the shelf on every letter you speak — but must turn around when you keep talking. The abort is the turnaround; debounce is waiting half a second to see if you will say another letter.
Requirements: What Makes a Great Solution?
Clarify scope before designing anything
Requirements Exploration Questions
Ask your interviewer these questions to refine requirements
What is the data source and scale?
- ·Local static array vs remote API (or hybrid)?
- ·Minimum characters before fetching? (usually 2-3)
- ·Max suggestions to show? (usually 5-10)
- ·Are results plain strings or rich objects (with icons, metadata)?
What are the interaction and accessibility expectations?
- ·Full keyboard navigation required? (arrows, enter, escape)
- ·Should it support free-text submit or only selection?
- ·Screen-reader support (ARIA combobox pattern)?
- ·Highlighting of matched text in results?
What are the performance and reliability requirements?
- ·Debounce delay (250-300ms typical)
- ·Caching strategy and TTL?
- ·Should we cancel in-flight requests on new keystrokes?
- ·Large result sets → virtualization needed?
Functional Requirements
Must Have — MVP
- ✓Input field that shows dropdown on focus + typing
- ✓Debounced search (local filter or API call)
- ✓Keyboard navigation (↑ ↓ Enter Esc)
- ✓Click-outside to close dropdown
- ✓Highlighting of matched query in suggestions
- ✓Loading, empty, and error states
- ✓Selection updates input and fires onSelect callback
Advanced (If Time Permits)
- +Rich suggestions with icons/metadata/images
- +Virtualized list for 1000+ results (react-window)
- +Recent searches / history section
- +Async data source with AbortController
- +Customizable filtering (fuzzy matching)
Non-Functional Requirements
Performance
- ·No API call on every keystroke (debounce + cache)
- ·Results render < 16ms (no layout thrash)
- ·Dropdown opens/closes without jank
Reliability
- ·Abort obsolete requests and guard every result/error update with active request identity
- ·Cache by query with an explicit freshness policy
- ·Offer retry when the active request fails
Accessibility
- ·role='combobox' + aria-expanded + aria-controls + aria-activedescendant
- ·aria-live region for status announcements
- ·Full keyboard operability (WCAG 2.1 AA)
Security / UX
- ·Sanitize displayed results to prevent XSS
- ·Clear input on Escape when no selection
- ·Support both mouse and keyboard selection
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.
- Full RADIO-framework walkthrough with architecture diagrams
- Data model, API design, and rendering strategy trade-offs
- Performance, accessibility, and offline sections plus a model answer
Already a member? Log in to open the workspace.