SD Mock · Design Typeahead Suggestion
Design a search typeahead like Google or Facebook on a live architecture board — drag components, wire them up, and defend your design to an expert interviewer who watches every move.
Start practiceCovers: Software Engineer
Your instructions
Design typeahead suggestion
A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
This is the rare question where a data structure — the trie — is the centerpiece. Prefix match is the easy part. The interview is making the trie O(1), updating it without stopping the world, and sharding a tree.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
- Notepad. Shared notes. Requirements, capacity math, schema, and end-of-session feedback live here. You can type in it too.
- Architecture board. Your design canvas. Drag typed components, wire them, label edges, mark scaled tiers as distributed. If it is not on the board, it is not in your design.
Build incrementally while you talk. Trace one keystroke — the "n" after "di" — end to end through your diagram to a ranked top-5 list. Argue the tradeoff, not "industry standard."
Design choices interviewers probe
Read this before you go in. These are the decisions, and why they matter.
Every keystroke is a request
Typing "dinner" sends six requests (q=d, q=di, … q=dinner) — about 20 per completed query. That ×20 multiplier is the single best estimation signal in this question. It drives the QPS that kills a database round-trip, and the client etiquette that cuts load: debounce ~50 ms, cancel in-flight requests, do not fire until 2–3 characters, browser-cache responses (Cache-Control: private, max-age=3600 — Google caches autocomplete for an hour).
The strawman: SQL LIKE
SELECT query FROM freq_table WHERE query LIKE 'din%' ORDER BY frequency DESC LIMIT 5 is a fine warm-up and works small. At ~24K QPS with a ~100 ms budget, the round-trip plus prefix scan breaks. State it, then volunteer the transition: the aggregated index is small (~3 GB of unique terms, ~25 GB with a year's growth), so the whole thing lives in memory as a trie. Elasticsearch's completion suggester is equally defensible if you can name its operational cost against a purpose-built trie.
Making the trie O(1)
The naive algorithm is three steps: find the prefix node — O(p); walk the subtree for completions — O(c); sort by frequency and take five — O(c log c). A popular short prefix has a huge subtree, and that blows 100 ms.
Two fixes. Cap prefix length (~50 chars) so the walk is constant. Cache the top five at every node — node "din" already holds its list. Query becomes find node + read list = O(1). Name the trade: space for time.
Know the cost. Bumping one query's frequency means updating the cached list in every ancestor up to the root. That is why nobody updates the serving trie in place. A space refinement: store references to terminal nodes plus frequencies, and reconstruct the phrase by walking parents — do not duplicate full strings on every node. Single-child chains can collapse into a radix / compressed trie.
More in System Design Interview Prep: AI Coach Edition
- SD Coach · The Data Layer
- SD Coach · Unique IDs and the URL Shortener
- SD Mock · Design Pastebin
- SD Coach · News Feeds and Typeahead
- SD Mock · Design Facebook News Feed
- SD Mock · Design Twitter
- SD Mock · Design Twitter Search
- SD Coach · Rate Limiting
- SD Mock · Design an API Rate Limiter
- SD Coach · Event-Driven Systems and Notifications
- SD Mock · Design a Notification System
- SD Coach · Async Jobs, Schedulers and Crawlers