Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Learned Search Autocomplete

Suggest completed queries within a tight latency budget at very high request rates, rank them with a model learned from logs and improve it iteratively, keep unsafe or empty suggestions out, and handle new queries, products and shoppers.

Problem statement

Design the machine learning system behind search autocomplete: as a shopper types in a search box, suggest completed queries. The design should cover serving at scale, a plan that improves the ranking in stages starting from a simple first version, and cold start.

For this exercise, assume a product search engine that searches products from many independent online stores. After each keystroke, the search box shows up to 8 suggested queries for the text typed so far; picking one runs that search.

A suggestion is good when the shopper picks it and the search it runs leads to a product the shopper clicks or adds to the cart.

For this exercise, also assume: - Suggestions can depend on the shopper's language, region and earlier searches in the same session. - Every suggestion must return at least one product, and phrases on a blocked list, such as offensive terms, must never be suggested.

A newly blocked phrase must stop appearing within minutes. - Shoppers search in several languages; each language's suggestions come only from searches and products in that language.

Ranking the product results after a search, spelling correction of a submitted query, sponsored suggestions and voice search are out of scope.

What to build

  1. As a shopper types, return up to 8 completed queries for the text so far, ranked so the one the shopper wants is near the top, using language, region and earlier searches in the session.
  2. Every suggestion runs a search that returns products, and blocked phrases are never suggested.
  3. Newly popular queries, newly listed products and brands, and shoppers with no history still get useful suggestions, and new candidates get a chance to be shown and learned from.
  4. Log what was suggested and picked, and improve the ranking in stages, each checked offline and then in an online experiment before it reaches every shopper.

At scale

  • For this exercise, assume about 30,000 searches a second at peak and about 8 suggestion requests per search, so about 240,000 suggestion requests a second; the server must return suggestions within 50 milliseconds at p99.
  • For this exercise, assume about 500 million distinct queries were searched in the last 90 days, most only once or twice, and the catalog holds about 300 million products, with about 1 million new products listed a day.
  • For this exercise, assume a query that suddenly becomes popular should be suggested within 15 minutes, and a newly listed product's name or brand within 1 hour.
  • For this exercise, assume about 25 billion searches a month (about 10,000 a second on average, against the 30,000 peak) are logged with the suggestions shown, their positions and what the shopper picked, and ranking models can be retrained daily.