Design the typeahead box for a large e-commerce site. As a user types, show the top 10 suggestions for the prefix, ranked by popularity. Suggestions update daily from search logs, and trending queries should appear within an hour.
Functional requirements
Return the top 10 suggestions for a prefix
Rank suggestions by popularity
Refresh suggestions from search logs
Filter offensive suggestions
Non-functional requirements
Suggestions return in under 100 ms at p95
The box keeps working if the ranking pipeline is down
Trending queries appear within one hour
Constraints and scale
10 million daily users, about 10 keystrokes per search
25 000 suggestion requests per second at peak
100 million distinct historical queries
You will practise
Precompute answers for hot prefixes
Cache aggressively at several layers
Separate the read path from a batch pipeline
Show 2 hints
Most traffic hits a small set of short prefixes: what does that suggest?
Does the ranking need to be computed on the request path?