Suggest the best completions after every keystroke, in a few milliseconds.
“Design search autocomplete, like the suggestions under the Google search box.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Splitting the system in two | Serving suggestions (fast, read-only) and building them (slow, offline) are different problems. A strong candidate draws them as two paths and does not mix them. |
| Latency thinking | Suggestions must appear while the user types. The budget is about 100 ms end to end, so every box, cache and network hop has to earn its place. |
| Choosing a data structure for a reason | A trie is the textbook answer. The interviewer wants to hear why a plain database query is too slow, and what to precompute at each prefix. |
| Freshness versus cost | Updating on every search is far too expensive. How often you rebuild, and how a trending search gets in quickly, is the real trade-off. |
| Product judgement | Ranking, blocked terms, personalisation and privacy all change what a good suggestion is. Naming them shows you think about users, not only servers. |
Autocomplete is a read-heavy lookup with a slow, separate data pipeline. For a typed prefix we return the top 5 most popular searches that start with it, in a few milliseconds. We never compute that at request time: the best 5 for every prefix are precomputed offline and kept in memory.
| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | How many suggestions, ranked by what, personal or global, latency, freshness, languages, safety. |
| 2. Estimate | 3 | Requests per second, size of the index, edge cache, write rate if updated live. |
| 3. API and data | 5 | One GET endpoint, the query log, the prefix to top-5 shape. |
| 4. High-level design | 8 | Two paths: serving and building. Name the cache layers. |
| 5. Deep dives | 15 | Top-5 precomputation, serving speed, build and update, then quality and edge cases. |
| 6. Scale and failures | 7 | Hot prefixes, a bad build, a node down, a viral spike. |
| 7. Wrap up | 3 | Recap, trade-offs, what you would add next. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| How many suggestions do we show, and how are they ranked? | The number sets the size of the precomputed list. The ranking rule decides what we count. | The top 5 (up to 10). Ranked by how often people search for them, newer searches counting more. | Store the top 5 at each prefix. Count with a time decay, not a plain total. |
| Are suggestions the same for everyone, or personal? | Personal results cannot be fully precomputed or cached at the edge for all users. | Global for now. Personal history can be a later improvement. | One shared index and a shared edge cache. Personalisation is an optional layer on top. |
| How fast must suggestions appear, and what is the latency budget? | This is the main non-functional requirement. It decides caching and where data lives. | Under 100 ms end to end at the 99th percentile, as the user types. | Everything on the read path is in memory. No database query at request time. |
| How fresh must they be? Does a breaking news search need to show within minutes? | Freshness decides how often we rebuild and whether we need a streaming lane. | Mostly stable, but a sudden surge should appear within about 10 minutes. | Hourly batch rebuild plus a small trending overlay from a stream job. |
| How many users and searches, and how long can a query be? | Turns into requests per second and the size of the index. | 10 million daily users, about 10 searches each. Prefixes up to 50 characters. | About 5 thousand requests a second, 25 thousand at peak. A prefix longer than 50 is ignored. |
| Which languages and regions? | Each language needs its own index, tokenisation and ranking, and may need its own region. | English first, designed so more languages can be added. | The index is keyed by language. Mention Unicode, and that some scripts need different handling. |
| Must we fix typos (did you mean)? | Typo tolerance needs fuzzy matching, which is a much bigger problem than prefix lookup. | Out of scope for now. Prefix match only. | A plain trie is enough. Say fuzzy matching is a later extension. |
| Are there things we must never suggest? | Offensive, illegal or private terms cause real harm and legal risk. | Yes. A block list, and a way to remove a suggestion quickly. | Filtering at build time, plus a fast removal path that does not wait for a rebuild. |
| Where does the input come from: a website, an app, or both? | Clients decide debounce, local caching and how many requests we really get. | Both. The client should not send a request on every keystroke. | Client debounce, cancel of old requests, and a short local cache are part of the design. |
| Do we need to keep working if the suggestion service is down? | Suggestions are helpful, not essential. Search itself must still work. | Yes. Search must never depend on suggestions. | The client treats failure as no suggestions. No retry storm. |
| Assumption | Value |
|---|---|
| Daily users | 10 million |
| Searches per user per day | 10 |
| Suggestion requests per search (after debounce) | about 4 |
| Peak compared with average | 5 times |
| Edge cache hit rate on suggestion requests | about 60% |
| Distinct searches kept in the index (after dropping the rare long tail) | 10 million, about 25 characters each |
| Trie size after sharing prefixes | about 100 million nodes |
| Memory per node (children plus the top 5 ids) | about 60 bytes |
| One suggestion server (all in memory) | about 10,000 lookups per second |
| Size of one response | about 500 bytes |
| Log line per completed search | about 100 bytes |
| What | Maths | Result |
|---|---|---|
| Searches per day | 10,000,000 × 10 | 100 million |
| Suggestion requests per day | 100,000,000 × 4 | 400 million |
| Requests per second (average) | 400,000,000 ÷ 86,400 | about 4,600, call it 5 thousand |
| Requests per second (peak) | 5,000 × 5 | 25 thousand |
| Reaching the origin at peak (40% miss the edge) | 25,000 × 0.4 | 10 thousand per second |
| Index memory (trie with top 5 per node) | 100,000,000 nodes × 60 bytes | 6 GB, fits on one machine |
| Servers needed at peak | 10,000 per second ÷ 10,000 per server, then × 2 for headroom | 2, so run 6 (two per zone, three zones) |
| Response bandwidth at peak | 25,000 × 500 bytes | 12.5 MB per second (about 100 Mbit/s) |
| Search log per day | 100,000,000 × 100 bytes | 10 GB per day (70 GB a week) |
| Log after 1 in 100 sampling | 10 GB ÷ 100 | about 100 MB per day |
| Writes per second if the top 5 were updated on every search | 100,000,000 × about 25 prefixes ÷ 86,400 | about 29 thousand per second |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| GET | /v1/suggest | ?q=wor&lang=en&limit=5 | 200 { v: 8421, q: "wor", suggestions: [{ text, score? }] } | No body, so it caches well. Cache-Control with a short max-age (about 60 s). Anonymous and cheap. An empty list for an unknown prefix, never an error. |
| POST | /v1/events/search | { q, lang, ts, session } | 202 Accepted | Sent by the search page when a search is completed, not on each keystroke. Goes to the log pipeline. Fire and forget. |
| POST | /v1/admin/blocks | { term, reason } | 201 { blockId } | Operators only. Takes effect on the next filter refresh (seconds), not the next rebuild. |
| GET | /v1/admin/index | none | 200 { liveVersion, builtAt, nodes, size } | For operations: which index version is live and how old it is. |
| Store | Key and value | Notes |
|---|---|---|
| Search log (Kafka, then files) | One line per completed search: time, query text, language, region | Append only. 10 GB a day. The source for counting. |
| Query counts (batch output) | query text → decayed count | Rebuilt on each run. About 10 million rows after dropping the rare tail. |
| Trie snapshot (the serving index) | prefix → top 5 [(text, score)], held as a trie in memory | A file of about 6 GB. Versioned (v8421). Loaded by every serving node. |
| Prefix table (alternative) | key: lang + prefix, value: the top 5 as a short list | Same data in a key-value store such as Redis. Easier to shard and update in place. |
| Block list | normalised term → reason | A tiny table, checked at build time and again at serve time. |
GET /v1/suggest?q=wor&lang=en&limit=5
{ "v": 8421, "q": "wor",
"suggestions": [ "world cup", "wordle", "world cup schedule", "world map", "word counter" ] }| Component | What it does |
|---|---|
| Client (browser, app) | Waits for a pause in typing (debounce, about 150 to 250 ms), cancels the request still in flight, and keeps a short local cache of answers it already has. |
| CDN / edge cache | Answers the most popular prefixes close to the user, for about a minute. About 60% of requests end here. |
| Suggestion servers | Stateless readers. Each holds the whole trie in memory and answers a prefix in microseconds. Easy to add copies. |
| Block filter | A small in-memory set of banned terms, checked on the way out. Lets us remove a suggestion in seconds. |
| Kafka search log | Receives one event per completed search. Sampled when volume is high. The source for counting. |
| Batch job and trie builder | Counts the log with a time decay, removes blocked terms, builds the trie with the top 5 at each node, and writes a versioned snapshot. |
| Snapshot store | Holds built indexes (object storage). Servers download the new one and swap to it. Old versions stay for a quick rollback. |
| Stream job and trend overlay | Counts only the last few minutes. Finds sudden risers and publishes a small list that suggestion servers merge in. |
The problem: A user types “wor”. We need the five best searches that start with it in a few milliseconds. The set of searches under a short prefix is huge, so we cannot find and rank them at request time.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Database query with LIKE | SELECT text FROM queries WHERE text LIKE 'wor%' ORDER BY count DESC LIMIT 5. | Trivial to write. Always has the latest counts. | Scans or walks a big index on every keystroke. A short prefix matches millions of rows, so it is slow and expensive at 25 thousand requests a second. |
| Plain trie, rank at request time | Walk to the prefix node, then walk the whole subtree, collect words, and take the top 5. | Simple. Small memory. The data structure is the textbook one. | A short prefix has a huge subtree. “w” would visit millions of nodes per request. The cost grows with the data, not with the length of the prefix. |
| Trie with the top 5 stored at every node | At build time, compute and store the best 5 at each node. At request time, walk to the node and read the list. | Lookup cost depends only on the prefix length (at most 50 steps). No sorting at request time. | More memory (a list at every node). Any change in counts means updating every ancestor node, so we rebuild in batches. |
| Prefix to top-5 table in a key-value store | Store one row per prefix: key lang + prefix, value the 5 strings. Skip the tree. | Simple to shard and cache. Easy to update one prefix. Any key-value store works. | More rows than trie nodes, since each prefix is stored in full. Repeats the strings at every prefix. |
A request becomes a walk of at most 50 steps and a read of five strings. Its cost does not depend on how much data there is. All the hard work (counting, ranking, picking the best five) happens at build time, where we have lots of time and no user waiting.
The price is memory and update cost: each node carries a list, and one new search can change the lists of all its ancestors. That is fine in a batch rebuild, and it is exactly why we do not update live. Store ids or short pointers to the strings instead of the strings themselves, so the lists stay small. See the Trie topic for how the structure itself works.
| Prefix | Top 5 stored at that node (example) |
|---|---|
| w | weather, world cup, weather today, wordle, web design |
| wo | world cup, wordle, world cup schedule, world map, wordle hint |
| wor | world cup, wordle, world cup schedule, world map, wordle hint |
| worl | world cup, world cup schedule, world map, world cup final, world news |
function suggest(prefix: string): string[] {
let node = root;
for (const ch of prefix.toLowerCase()) { // at most 50 steps
node = node.children.get(ch);
if (!node) return []; // unknown prefix: no suggestions
}
return node.top5; // precomputed at build time
}The problem: The answer must appear while the user is typing, in under 100 ms, for 25 thousand requests a second at peak. The lookup is quick, so the time goes on the network, on useless requests, and on a few prefixes that everyone types.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Ask on every keystroke | The client sends one request per character. | The simplest client. Always the newest prefix. | A 10-letter search is 10 requests, and most are out of date before the answer arrives. It multiplies server load for nothing. |
| Debounce and cancel on the client | Wait about 150 to 250 ms for a pause, send once, and cancel any request still in flight. | Cuts requests by a large share (about 40 to 60% in this model). No server work. | The user waits the debounce time before the first answer. Too long feels slow, too short saves little. |
| Edge cache for popular prefixes | Allow the CDN to cache GET /suggest for about a minute. The URL is the key. | Answers close to the user and takes 60% of load off the origin. Free scaling for hot prefixes. | Suggestions can be up to a minute old. Rare prefixes miss, so the cache helps the head, not the tail. |
| Shard the index by prefix | Split the trie: node group A owns words starting a to f, and so on. Route by the first characters. | Each node holds less data. | The index is only 6 GB, so this is not needed for size. It creates hot shards (“s”, “a”) and complicates routing and failure. |
The cheapest request is the one never sent, and the next cheapest is one answered at the edge. Debounce removes about half of the requests, and the edge removes most of the rest of the popular ones, so the origin sees roughly 10 thousand a second at peak. A handful of servers is enough, so we do not shard.
Because every server holds a full copy, any server can answer any prefix. There are no hot shards, no routing rule and no single node that matters. Failure handling is just “try another server”. We keep replicas in three zones and scale by adding copies.
| Layer | What it saves | Staleness |
|---|---|---|
| Client debounce and cancel | About half of all requests never leave the device | None |
| Client local cache | Typing a letter and deleting it again costs nothing | Seconds, per session |
| CDN / edge cache | About 60% of the remaining requests | Up to a minute |
| Suggestion server memory | No disk, no database, microsecond lookups | Until the next snapshot |
The problem: Popularity changes. Last week's top search fades and today's surge has to appear. But every search touches the top-5 lists of all its prefixes, and short prefixes are shared by almost everyone, so updating live means a flood of writes onto a few very hot nodes.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Update on every search (live) | For each completed search, update the count and fix the top 5 at every prefix of the query. | Always current. | About 29 thousand writes a second, and the shortest prefixes get a write from nearly every search. Hot nodes, locks, and a lot of churn for tiny changes in ranking. |
| Periodic batch rebuild | Every hour or day, count the log offline, build a new trie, ship a snapshot. | Cheap, simple and easy to test. Serving nodes are read-only. Easy rollback to the last good version. | Stale between runs. A surge waits for the next build. |
| Batch plus a trending overlay | Batch builds the stable index. A stream job watches the last 15 minutes and publishes a small list of risers that servers merge at request time. | Fresh for what matters (surges), cheap for the rest. Keeps the read path simple. | Two systems and a merge step. The overlay needs care so it cannot flood the list with junk. |
| Sample the log and keep counts in a sketch | Keep only 1 in 100 events, or count in a Count-Min Sketch and keep heavy hitters. | Shrinks the data and the cost by two orders of magnitude. Popular searches survive sampling. | Rare searches vanish from the counts. Counts become estimates, which is fine for ranking. |
Ranking does not need exact counts. A search that is twice as popular still ranks higher with a 1 in 100 sample, so we sample, and the log goes from 10 GB to about 100 MB a day. The batch job is then trivial to run, and the whole index is rebuilt rather than patched, so the serving path never writes.
The cost of batch is staleness, so we add the overlay only for the case where staleness hurts: a sudden surge. The stream job counts the last few minutes, compares them with the normal rate, and publishes the top few risers for the overlay. Deploy the new index as a versioned snapshot, load it beside the old one, switch, and keep the old one for rollback.
score(query) = sum over days d of count(query, d) × 0.5^(age_in_days(d) / half_life) half_life = 7 days → yesterday counts ~90%, a week ago 50%, two weeks ago 25% Today's count is the total only for today; trending uses a much shorter window (15 min).
| Step | Detail | Why |
|---|---|---|
| Sample | Keep 1 in 100 completed searches (or all, if volume is small) | Ranking survives sampling. Cost drops 100 times. |
| Normalise | Lowercase, trim, collapse spaces, strip odd characters | “Weather” and “weather ” must count as one |
| Filter | Drop blocked terms, personal data patterns, very short or rare queries | Safety, privacy and a smaller index |
| Count with decay | Weighted sum above | Recent behaviour wins, old fades |
| Build and verify | Trie plus top 5, then test sample prefixes against the last version | Catch a bad build before it ships |
| Ship and swap | Versioned snapshot, load beside the old one, switch node by node, keep the old one | Zero downtime and instant rollback |
The problem: Fast is not enough. Suggestions must be useful, safe and fair. Popularity alone ranks the wrong things, a single offensive suggestion is a headline, and every language and user needs something a bit different.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Pure popularity | Rank by decayed search count only. | Simple and explainable. Works well for most prefixes. | Old giants crowd out new things. No sense of intent, place or person. Can surface harmful terms. |
| Popularity with safety filters | Same ranking, plus a block list, patterns for private data, and a fast removal path. | Removes the worst risks cheaply. Block list works at build time and serve time. | Needs people to maintain the list. Cannot catch everything. |
| Blend global and personal | Look up the global top 5, then mix in the user's own recent searches, ranked first. | Feels smart and relevant. Works for repeat searches. | Cannot be cached at the edge per user. Needs privacy care. More work per request. |
| Learned ranking | Use click and selection data to train a model that scores candidates (frequency, recency, location, device). | Best quality. Learns what people actually pick. | More infrastructure and monitoring. Harder to explain. A later step, not the first version. |
Start with what is reliable: a decayed popularity score and a strong safety filter. These give most of the value with a design that stays simple and cacheable. Personalisation is a thin layer: the global answer is shared and cached, and the user's own recent searches (kept on the device or in a small per-user store) are merged in front at the end, so the main path stays the same.
Measure the quality instead of arguing about it. Track how often a user picks a suggestion, how far down the list they pick (mean reciprocal rank), and how many keystrokes suggestions save. Run A/B tests on ranking changes, and use the results to decide if a learned ranker is worth building.
| Concern | Approach |
|---|---|
| Offensive or illegal terms | Block list applied when building, and again at serve time. An operator can add a term and it disappears in seconds. |
| Private data in the log (names, emails, numbers) | Pattern filters, minimum count threshold (a query must be searched by many different users to be kept), and a short retention period. |
| Many languages | One index per language, tokenisation and normalisation per script. Right-to-left and no-space scripts need their own handling. Pick the index from the language header or setting. |
| Location and time | A small regional index for strong local effects (city names, local events), used as a boost on top of the global one. |
| Ties and stability | Break ties by a fixed rule (score, then alphabetical), so the list does not flicker between builds. |
| Cold start for a new term | The trending overlay promotes it once it surges. A brand new term with few searches is correctly ignored. |
| Prefix | Next key in | What happened |
|---|---|---|
| w | 110 ms | skipped: next key came in under 150 ms |
| wo | 95 ms | sent, answered by the edge |
The last full rebuild finished at minute 0. At minute 70, “world cup final” starts to surge. How long until it can show in suggestions?
A simplified model with fixed numbers (no random values). Counts are searches this week. A prefix is “popular” when at least 800 searches sit under it. Latencies (20 ms edge, 70 ms origin) and the typing pattern are illustrative. The rebuild lag is the time to the next rebuild after minute 70.
| Bottleneck | Fix |
|---|---|
| Hot prefixes (“a”, “s”, “the”) get a huge share of requests | Cache them at the edge for about a minute. Every server holds a full copy, so any node can answer. No hot shard exists. |
| Request volume grows 10 times | Add stateless suggestion servers (the index is read-only), put more of the answers in the CDN, and tighten the debounce on the client. |
| Index grows past one machine's memory | Compress it (radix trie, shorter stored prefix, ids instead of strings), drop the rare long tail, or split by language. Only then shard by prefix. |
| Build job gets slow as the log grows | Sample the log, count with a distributed job, and keep incremental counts (yesterday's count plus today's) instead of re-reading everything. |
| Snapshot download storms (many servers fetch 6 GB at once) | Stagger the rollout, use a peer-to-peer or tiered cache for files, and compress the snapshot. |
| Trend overlay noise | Require a minimum number of different users and a clear jump over the normal rate. Cap the overlay at a few entries per prefix. |
| Failure | How the design copes |
|---|---|
| A suggestion server dies | The load balancer health check removes it. Any other node has the full index, so nothing is lost. The client treats a timeout as no suggestions. |
| A bad index is built (empty, wrong, or full of junk) | Verification before shipping (size, sample prefixes, comparison with the last version). Keep the old version and roll back by pointing servers to it. |
| The batch job fails or is late | Servers keep serving the last good snapshot. Suggestions get a little stale. Alert if the index is older than a threshold. |
| Kafka or the log pipeline is down | Search events are fire-and-forget, so searching is unaffected. Buffer in the producer for a short time, then drop. Counts for that period are lower. |
| A query goes viral in minutes | The stream job's overlay promotes it in about 5 minutes, and the CDN's short max-age lets the new answer through. Hourly rebuild includes it after. |
| An offensive suggestion is reported | Add it to the block list. The serve-time filter removes it in seconds, and the next build drops it. Purge the CDN entries for the affected prefixes. |
Autocomplete is a fast read path over a precomputed index, fed by a slow offline pipeline. The client debounces and a CDN answers popular prefixes. Stateless suggestion servers hold a six gigabyte trie with the top five stored at every node, so a lookup is a short walk and a read. A batch job counts a sampled, time-decayed search log and ships a versioned snapshot every hour, with a small streaming overlay for trending searches. Safety filters, a distinct-user threshold and a thin personal layer keep the suggestions good and safe.
| Decision | What we gain | What it costs |
|---|---|---|
| Precompute the top 5 at every node | A lookup costs the prefix length, not the data size. No sorting at request time. | More memory, and any change needs a rebuild of the ancestors. |
| Batch rebuild instead of live updates | No hot writes. Read-only servers, easy rollback. | Suggestions are up to an hour stale without the overlay. |
| Full copy of the index on every server | No sharding, no hot shards, any node can answer. | Memory per node and big snapshot downloads. Works only while the index fits. |
| Edge cache with a one-minute lifetime | About 60% less load, answers close to the user. | A removed suggestion can linger for up to a minute unless purged. |
| Sample the log and use decayed counts | 100 times less data, and recent behaviour wins. | Counts are estimates, and the rare long tail is lost. |
| Global answers with a thin personal layer | Shared caching stays possible. Personal feel where it matters. | More work per request for signed-in users, and privacy care. |
The interviewer wants to hear you remove work, not only speed it up.
They want to see that you chose the structure for a reason, and know what it costs.
This is where interviewers separate a memorised answer from a thought-through one.
Expect the interviewer to break something and ask what happens.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| Suggestions must be personal to each user | Keep the global index and cache. Add a per-user layer (device history or a small per-user store) merged in front at the end, with a strict timeout and a global fallback. Care about privacy and retention. |
| Typo tolerance, such as suggesting weather for wether | Prefix match is not enough. Add fuzzy matching with an edit-distance index, or a second index of common misspellings mapped to the right query. Costs more memory and CPU per request. |
| Results must be fresh within a minute everywhere | A bigger streaming path, a very short CDN lifetime, and frequent overlay updates. Costs more load on the origin and a more complex pipeline. Say what freshness is really worth. |
| Autocomplete for a catalogue of 100 million products (not searches) | Data comes from the catalogue, not a log. Rank by sales and popularity, update on catalogue changes, and consider a search engine with prefix queries because filtering by category is needed too. |
| Support suggestions inside the middle of a phrase, not only the start | A trie only matches the start. Index every word (or n-gram) and use an inverted index, or a suffix structure. More memory, and more work to rank across words. |
| The index grows to 500 GB (many languages, long tail) | Split by language and region first, then shard by prefix with replicas for hot prefixes. Add routing, and plan for hot shards and a scatter rule for short prefixes. |
| Suggestions must work offline on a phone | Ship a small compressed index of the most popular few hundred thousand queries to the device, and refresh it daily. Local lookup, no network. |
| Add rich suggestions (people, places, products with pictures) | Entities have ids and metadata, so the trie stores ids and a second lookup fetches the card. More data per answer and more caching rules. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Requirements | Starts drawing a trie. Never asks about ranking, freshness, personalisation or safety. | Asks for the number of suggestions, ranking, latency, freshness and scale, and writes them down. | Also asks what must never be suggested, whether search must survive a suggestion outage, and states what is out of scope (typos, personal history). |
| Estimation | No numbers, or says the data is huge. | Requests per second, index size and the log size, with correct arithmetic. | Finds the number that drives the design: 6 GB means a full copy on every server, and 29 thousand live writes a second argues against live updates. |
| Design | One box called autocomplete service with a database behind it. | A trie with the top five at each node, a cache layer, and a separate offline build. | Draws two clear paths, serving and building, with versioned snapshots, an overlay for trends, and fast removal for blocked terms. |
| Deep dive depth | Says use a trie and stops. | Explains precomputing the top five, debounce and caching, and batch building. | Compares at least three options for each hard part, with costs: LIKE against trie against stored top five, live against batch, shard against copy. |
| Trade-offs and failure | Assumes everything works and everything is fresh. | Names staleness, memory and a bad build as risks, with a rollback. | Quantifies the trade-offs, handles a viral query, a bad index, and an offensive suggestion, and says what would change at 10 times scale. |
| Communication | Jumps between topics and lists techniques. | Follows the steps in order and explains choices. | Summarises after each step, checks in with the interviewer, and speaks about users and product quality, not only servers. |
| Mistake | Do this instead |
|---|---|
| Running a database query with LIKE on each keystroke | Precompute the top five per prefix and serve from memory. Say why the query cannot keep up. |
| Ranking at request time by walking the subtree | Store the best five at every node during the build, so a request is a short walk and a read. |
| Updating the index on every search | Do the maths: about 29 thousand writes a second on hot nodes. Rebuild in batches, and add a small trending overlay. |
| Sending a request on every keystroke | Debounce on the client, cancel old requests, and cache answers locally. |
| Sharding a 6 GB index | Put a full copy on every server. Shard only when the index will not fit, and say why you would not do it earlier. |
| Ignoring safety and privacy | Block list at build and serve time, a distinct-user threshold, short log retention, and a fast removal path. |
| Mixing the serving path and the build path in one drawing | Draw them as two paths with different speed needs, joined by a versioned snapshot. |
| Forgetting a rollback for a bad index | Version the snapshot, verify it before switching, switch gradually, and keep the last good one. |
The data structure itself: how a trie stores and finds prefixes.
Cache-aside, expiry and what to cache at each layer.
How popular prefixes are answered close to the user.
Counting a huge stream with a tiny, fixed amount of memory.
How the best 5 are kept at each node.
The offline rebuild and the trending lane.
The search log that feeds the counts.
Why short, popular prefixes are an edge-cache problem.