Fernvale Market asks for search suggestions that keep up with typing. The fictional workload is 8,640,000 searches a day with 5 keystrokes each and a peak three times the average. Deliver the scope, a peak keystroke estimate, a suggestion API, a precomputed prefix table, the online and offline paths, a trending-phrase plan and a blocked-phrase fix.
How interviewers level this design
- Junior: separates the offline counting job from the request path and returns suggestions with one lookup.
- Mid-level: sizes the keystroke load, caches hot prefixes and handles out-of-order responses.
- Senior: designs freshness for trending phrases, guarantees removals and explains how prefix tables are sharded and rebuilt.
Fernvale Market wants suggestions to appear as shoppers type in the search box. Each keystroke is a request, so the read rate is several times the number of searches, and every answer must arrive in well under the time between keystrokes. The suggestions themselves come from yesterday's and today's search logs.
That shape splits the design in two. An offline path counts queries and precomputes the top phrases for every prefix. An online path answers a prefix with a single lookup, ideally from a cache. You will size the keystroke load, define the API and the precomputed table, draw both paths, then handle the two cases interviewers like to add: a phrase that suddenly trends and a phrase that must disappear right away.
Precompute top suggestions per prefix offline and serve each keystroke with one cached lookup.