Chaturmind
LearnDSASystem DesignDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Β© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← System Design Interview Playbook

Interview Framework

  • The 6-Step Design Framework
  • HLD Fundamentals Refresher
  • Requirement Gathering Practice
  • Domain Decomposition
  • API Contract Design
  • Data Ownership Model
  • Failure Scenario Walkthroughs
  • Architecture Diagramming
  • Back-of-Envelope Estimation

10 Case Studies

  • Design a URL Shortener
  • Design Twitter / X
  • Design WhatsApp
  • Design Netflix
  • Design a Rate Limiter
  • Design a Search Autocomplete
  • Design a Distributed Cache
  • Design a Notification Service
  • Design Uber / Ride Sharing
  • Design a Distributed File Storage System
  • Design a Distributed Task Scheduler
  • Design a Message Queue System
  • Design an Authentication System at Scale
  • Design a Distributed Logging & Metrics Pipeline
  • Design a Food Delivery Platform
  • Design a Real-Time Analytics Dashboard
  • Design a Monitoring & Alerting System
  • Design Container Orchestration Basics
  • Design a CI/CD Pipeline System
  • Design Service Mesh Basics
  • Design a Centralized Configuration & Secrets System
  • Design a Batch Processing System
  • Design a Data Warehouse / Analytics Storage Layer
  • Design Global Content Delivery
  • Case studies

    πŸ—οΈDesign a URL Shortener
  • πŸ—οΈDesign a Rate Limiter
  • πŸ—οΈDesign Twitter / X
  • πŸ—οΈDesign WhatsApp
  • πŸ—οΈDesign Netflix
  • πŸ—οΈDesign a Distributed Cache
  • πŸ—οΈDesign a Notification Service
  • πŸ—οΈDesign a Search Autocomplete System
  • πŸ—οΈDesign Uber / Ride Sharing
  • πŸ—οΈDesign a Web Crawler
  • πŸ—οΈDesign a Payment System
  • πŸ—οΈDesign a Distributed Lock Service
  • πŸ—οΈDesign a Video Streaming Platform
  • πŸ—οΈDesign a Search Engine
  • πŸ—οΈDesign E-Commerce Checkout & Inventory at Scale
Chaturmind
← System Design Interview Playbook

Interview Framework

  • The 6-Step Design Framework
  • HLD Fundamentals Refresher
  • Requirement Gathering Practice
  • Domain Decomposition
  • API Contract Design
  • Data Ownership Model
  • Failure Scenario Walkthroughs
  • Architecture Diagramming
  • Back-of-Envelope Estimation

10 Case Studies

  • Design a URL Shortener
  • Design Twitter / X
  • Design WhatsApp
  • Design Netflix
  • Design a Rate Limiter
  • Design a Search Autocomplete
  • Design a Distributed Cache
  • Design a Notification Service
  • Design Uber / Ride Sharing
  • Design a Distributed File Storage System
  • Design a Distributed Task Scheduler
  • Design a Message Queue System
  • Design an Authentication System at Scale
  • Design a Distributed Logging & Metrics Pipeline
  • Design a Food Delivery Platform
  • Design a Real-Time Analytics Dashboard
  • Design a Monitoring & Alerting System
  • Design Container Orchestration Basics
  • Design a CI/CD Pipeline System
  • Design Service Mesh Basics
  • Design a Centralized Configuration & Secrets System
  • Design a Batch Processing System
  • Design a Data Warehouse / Analytics Storage Layer
  • Design Global Content Delivery
  • Case studies

    πŸ—οΈDesign a URL Shortener
  • πŸ—οΈDesign a Rate Limiter
  • πŸ—οΈDesign Twitter / X
  • πŸ—οΈDesign WhatsApp
  • πŸ—οΈDesign Netflix
  • πŸ—οΈDesign a Distributed Cache
  • πŸ—οΈDesign a Notification Service
  • πŸ—οΈDesign a Search Autocomplete System
  • πŸ—οΈDesign Uber / Ride Sharing
  • πŸ—οΈDesign a Web Crawler
  • πŸ—οΈDesign a Payment System
  • πŸ—οΈDesign a Distributed Lock Service
  • πŸ—οΈDesign a Video Streaming Platform
  • πŸ—οΈDesign a Search Engine
  • πŸ—οΈDesign E-Commerce Checkout & Inventory at Scale
HomeLearnSystem DesignSystem Design Interview Playbook10 Case Studies
βœ“ FreeAdvancedΒ· 6 min read

Design a Search Autocomplete

How to run the autocomplete design in a 45-minute interview: the precomputed top-K trie, offline index builds, edge caching, and the follow-ups to expect.

Published September 21, 2026


Design a Search Autocomplete β€” the 45-minute interview walkthrough

This lesson is the interview version: the order to present the design, the numbers to state, and the trade-offs to defend. The full reference design is the case study Design a Search Autocomplete System in this chapter.

Autocomplete (typeahead) shows the most likely completions while a user types: "how to" β†’ "how to tie a tie", "how to screenshot on mac". The defining constraint is latency: suggestions must appear in well under 100 ms, on every keystroke, for millions of users. That single constraint drives almost every decision.

Minutes 0–5: clarify requirements

  • What ranks suggestions? Usually query popularity, optionally blended with freshness (trending) and personalization.
  • How many suggestions? Typically 5–10.
  • Latency budget? p99 under ~100 ms end to end, which leaves maybe 10–20 ms for the server.
  • Scale? Say 5 billion searches/day. Each search produces several keystroke requests (users type ~4–6 characters before choosing), so tens of billions of autocomplete requests/day, peaking in the hundreds of thousands per second.
  • Freshness? Does a query trending right now need to appear within minutes, or is daily enough?
  • Filtering? Offensive or unsafe suggestions must be removable quickly.

The key realization to say aloud: this is overwhelmingly read-heavy, and suggestions don't need to be real-time exact. That lets you precompute almost everything.

Minutes 5–15: the high-level design

There are two separate paths, and separating them is the core idea:

QUERY PATH (fast, read-only)                      DATA PATH (offline, batch)

 user types "app"                                  search logs
      β”‚                                                 β”‚
      β–Ό                                                 β–Ό
 CDN / edge cache ── hit ──▢ suggestions         stream/batch aggregation
      β”‚ miss                                     (count queries per time window)
      β–Ό                                                 β”‚
 Autocomplete service                                   β–Ό
 (in-memory prefix index, top-K per prefix)  ◀──  index builder: build trie with
                                                  top-K precomputed per prefix,
                                                  publish a new version every N minutes
  • Query path: look up the prefix in an in-memory structure that already holds the answer. No computation at request time.
  • Data path: aggregate search logs into query counts, build the index offline, and swap it into the servers periodically.

Minutes 15–35: the deep dives

1. The data structure: a trie with precomputed top-K

A trie (prefix tree) stores strings character by character, so all queries starting with "app" live under one node. Finding that node takes O(length of prefix) steps.

The naive approach finds the node and then walks its entire subtree to rank completions, which is far too slow for popular short prefixes like "a". The standard fix is to store the top-K completions directly on every node during the offline build. A lookup then becomes: walk ~3–10 nodes, return a stored list. That's constant-ish time at query time, paid for with extra memory and a slower build.

Memory estimate: with ~100 million distinct popular queries, the trie plus top-K lists fits in tens of GB. That's feasible on large-memory servers, or you can shard by prefix range (a–f, g–m, …) with a thin router in front. Sharding by first letter is uneven ("s" is far busier than "x"), so shard by measured traffic.

2. Keeping it fresh without updating on every search

Updating the trie on every search would mean constant writes to a structure being read at hundreds of thousands of requests per second. Instead:

  • Aggregate counts in time windows (hourly or every few minutes) from the log stream.
  • Rebuild the index (or rebuild only changed branches) and atomically swap the new version in, with blue/green loading on each server.
  • For trending queries, keep a small, separate short-window index and blend its results in at query time, rather than rebuilding everything every minute.

3. Taking load off the servers

  • Client side: debounce keystrokes (send after ~100–150 ms of no typing), and don't query for 1–2 character prefixes if they're not useful. Cache results locally as the user types and deletes.
  • Edge/CDN caching: the popular prefixes are a small set that accounts for most traffic. Cache their responses at the edge with a TTL matching the index refresh.
  • Server side: the in-memory index is the cache, so there's no database on the hot path at all.

4. Ranking and personalization

Base ranking is popularity, weighted toward recent activity (for example exponential decay). Personalization (your own recent searches, your location, your language) is blended in at query time from a small per-user store. Keep it lightweight so latency doesn't suffer.

Minutes 35–45: trade-offs and wrap-up

  • Precompute vs compute at query time: we trade memory and build complexity for predictable, tiny latency.
  • Freshness vs cost: batch rebuilds every N minutes, plus a trending overlay, instead of real-time updates.
  • Blocklist: a filter applied at query time (not only at build time), so an offensive suggestion can be removed within minutes.
  • With more time: multi-language support, spelling correction ("fuzzy" prefixes), A/B testing ranking models.

Common mistakes in interviews

  • Querying a database with LIKE 'app%' on every keystroke. Even with an index it won't hit the latency target at this scale, and ranking needs aggregation.
  • Traversing the trie subtree at request time instead of storing top-K per node.
  • Updating the trie synchronously on each search.
  • Forgetting client-side debouncing, the cheapest large win.

Follow-up questions this topic invites β€” and their answers

Q: How big can the top-K lists make the trie? A: Each node stores K references (for example 10 query IDs, not full strings), so memory grows with nodes Γ— K. You bound it by only including queries above a popularity threshold, storing IDs into a shared string table, and pruning deep, rare branches. If it still doesn't fit on one machine, shard by prefix range.

Q: How do you remove an offensive suggestion immediately? A: Apply a blocklist filter at query time in the service (and at the edge cache by purging affected prefixes), so removal doesn't wait for the next index build. The next build then drops it from the data too.

Q: Why not use Elasticsearch's completion suggester? A: For moderate scale it's a perfectly good choice and much less custom code. At very large scale and very strict latency, a purpose-built in-memory index gives more control over memory layout, ranking and update strategy. In an interview, mention it as the pragmatic option, then explain what the custom design buys.

Q: How would you handle typos? A: Add a fuzzy-matching step for prefixes that return few results: an edit-distance search over a limited neighbourhood, or a separate "did you mean" index built from common misspellings in the logs. Keep it off the fast path for normal prefixes.

Previous

Design a Rate Limiter

Next

Design a Distributed Cache

AI Tutor

Lesson: Design a Search Autocomplete

Quick actions

AI responses can be inaccurate. Verify critical information.