Frontend

Designing an Autocomplete / Search System in Frontend

Autocomplete is a widely used UI pattern seen in search bars, mentions, and suggestions across products. The goal is to fetch and display relevant suggestions as the user types, while ensuring performance, responsiveness, and correctness. This problem tests how you handle user input, API interaction, caching, and race conditions in real-time systems.

ByteAndBites·Jul 04, 2026
Designing an Autocomplete / Search System in Frontend
You are asked to design a search autocomplete system similar to a search bar.

Requirements:
  • Show suggestions as user types
  • Fetch results from backend dynamically
  • Display results in dropdown
  • Handle fast typing efficiently
  • Avoid unnecessary API calls
  • Maintain responsiveness

Follow-ups:
  • How do you prevent too many API calls?
  • How do you handle stale responses?
  • How do you cache results?
  • What happens when network is slow?
  • How do you debounce input?

How to Think About It (Framework)
  1. Input Handling
  2. Data Fetching
  3. State Management
  4. Caching Strategy
  5. Performance Optimization
  6. Edge Cases

Input Handling
Core idea:
  • Listen to user input changes
  • Trigger search only after some delay
Technique:
  • Debouncing (most important concept here)
Without debounce:
  • API called on every keystroke
With debounce:
  • API called after user pauses typing

Data Fetching
Typical API:
GET /search?q=apple
Important:
  • Each query returns suggestions list
Challenges:
  • Multiple in-flight requests
  • Out-of-order responses
Solution:
  • Track latest query
  • Ignore stale responses
Data Layer
Data Layer

State Management

We need to manage:
  • query: current input value
  • results: suggestions list
  • loading: request in progress
  • error: failure state
  • activeIndex: for keyboard navigation
Important:
  • Always tie results to current query

Caching Strategy
Basic caching:
  • Cache results by query string
Example:
  • "app" → cached results
  • "apple" → separate cache
Benefits:
  • Avoid repeated API calls
  • Instant results for repeated queries
Advanced:
  • LRU cache (limit memory)
  • Partial matching reuse (optional)

Performance Optimization
  1. Debouncing: Delay API calls (300ms typical)
  2. Request Cancellation: Abort previous request (AbortController)
  3. Avoid Re-renders: Memoize components
  4. Limit Results: Show top N results

Handling Race Conditions
Problem:
User types fast → multiple requests → responses arrive out of order
Solution:
  • Keep track of latest query
  • Only update UI if response matches current query

User Experience Considerations
  • Show loading indicator
  • Highlight matched text
  • Keyboard navigation (↑ ↓ Enter)
  • Close dropdown on blur
  • Show “No results” state


Simple Flow
  1. User types input
  2. Debounce triggers
  3. API request sent
  4. Response received
  5. Validate response (latest query)
  6. Update results
  7. Render dropdown
Flow Chart for Autocomplete
Flow Chart for Autocomplete
What Interviewer is Testing
  • Understanding of debouncing
  • Handling async race conditions
  • Efficient API usage and Cancellation
  • Caching awareness
  • UX thinking

System DesignInterviewAtlassianReactJavascriptAutocompleteGoogle
Frontend System Design Playbook
Series
Frontend System Design Playbook
View series
A hands-on series focused on cracking frontend system design interviews at companies like Google, Atlassian, and Uber. Instead of theory-heavy discussions, this series breaks down real UI systems—like infinite scroll, autocomplete, caching, and complex state management—into clear, practical approaches with implementation-focused thinking.