Lesson 12 of 15
34. Design Search Autocomplete (Typeahead)

Score yourself

3 min read+10 XP

Score yourself

Give yourself 0, 1 or 2 points per row.

Area0 points1 point2 points
RequirementsStarted drawingListed featuresLatency per keystroke, freshness and safety agreed
EstimatesNoneNumbers, not used laterNumbers that showed reads must be memory lookups and the tail must be pruned
API and dataSkippedAPI or store, not bothCacheable GET, debounce, prefix → top-K store with versions
High-level designQueries the database per keystrokeRead path onlyRead path and offline/streaming build path, with atomic publish
Deep diveHand-wavedTrie describedTop-K per prefix, trend blending or multi-layer caching done properly
Trade-offsNone namedNamed when askedRaised unprompted (freshness vs cache, manipulation, storage vs speed)
CommunicationLong silencesMostly clearThought out loud, checked in, managed time

12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.

The bar: fresher vs SDE-2

FresherSDE-2
Data structureTrie, walked per requestTop-K per prefix, served from a flat table
Building"Update counts on every search"Offline batch + streaming trends, atomic publish
FreshnessRebuild dailyDecayed recency blended with long-term popularity
ScaleOne serverSharded in-memory store, CDN and client caching, hot short prefixes
SafetyNot mentionedFilters, unique-user counts, purge path

Common mistakes

  • Running a search query or a SQL LIKE 'dat%' per keystroke.
  • Walking the trie's subtree at request time for short prefixes.
  • Writing to the trie on every search, mixing heavy writes into the read path.
  • No debounce or client cache, multiplying traffic.
  • Ignoring manipulation and offensive suggestions.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz