advanced
Search autocomplete
Design prefix indexes, ranking, personalization, update pipelines, latency budgets, and fallback behavior.
Autocomplete suggests queries as users type with strict latency budgets (often under 50–100 ms p99). Use prefix indexes — trie, Elasticsearch completion suggester, or dedicated prefix tables — fed by an offline or streaming update pipeline from search logs and catalog changes.
Ranking blends popularity, personalization, locale, and freshness. Debounce client requests and cache hot prefixes at CDN or edge. Fallback to trending queries when index lags or fails.
On interviews: data pipeline from queries to prefix index, ranking signals for "ap" → "apple", and degradation on backend timeout.
Common pitfalls: hitting primary database with LIKE prefix queries; no debounce causing query storms; stale suggestions after catalog rename.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Prefix index structure for fast lookup.
- Async update pipeline from query logs.
- Rank by popularity and personalization.
- Cache hot prefixes and define fallback.