← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 009 · Caching

Design Search Autocomplete

Medium 40 min

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
  1. Most traffic hits a small set of short prefixes: what does that suggest?
  2. Does the ranking need to be computed on the request path?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • The ranking pipeline failsThe nightly job that recomputes suggestions crashes and does not run for two days.

Run them from the workspace once your design is in place.