SD-8 · Back to the write-up
Design a Typeahead Autocomplete
Precompute the top 10 for every prefix offline, keep the whole trie in memory on every server, and let the edge answer the common prefixes.
Follow a request
Type · edge hit
Type · edge miss
A search is logged
Nightly build
A trend appears
A bad build
Clients
Edge
Serving
Pipeline
Search boxDebounced
Search serviceRuns searches
Edge cache60% of prefixes
Suggest serversTrie in memory
Trending storeRising queries
Search logEvent stream
Trend counterLast 15 min
Query counts30 days
Trie builderNightly
Snapshot storageBuilt tries
The numbers, at a glance
1 search ≈ 50,000/s6 requests ≈ 300,000/s
600K/sKeys
300K/sSent
120K/sServers
60% at the edge40% suggest servers
A keystroke, in order
Edge miss shown. On a hit, the edge answers and the suggest server and trending store disappear.
Search box
Edge cache
Suggest server
Trending store
1 GET ?q=new yo&locale=en-US
2 miss
3 refresh local copy (every 30 s)
4 top 10 + trend, filtered
5 200, max-age 60
RequestResponseAsync, does not block
How a prefix becomes 10 answers
The decision this question is really about.
GET ?q=ne
LIKE 'ne%' ORDER BY count
2,000/s per DB
+ Always current.− Reads and sorts millions of rows per key.
search
update 12 prefixes × N replicas
reads wait on locks
+ Fresh on every search.− Every replica takes every write.
nightly build
n → e → top 10+ trends
edge caches short prefixes
+ Microsecond lookups, read-only.− Needs a pipeline and a trend layer.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Search box
App server
SQL database
Search box
Load balancer
Suggest servers
Search logTrie builderSnapshot storage
Search box
Edge cache
Load balancer
Suggest serversTrending store
Search logTrend counterTrie builder
Was this walkthrough useful?Your vote tells us what to improve next.