34. Design Search Autocomplete (Typeahead)
1
The interview prompt2
34.1 What do you ask first?3
34.2 How big is this, really?4
34.3 What are the doors?5
34.4 What do we store?6
34.5 What does the whole system look like?7
34.6 Trie or prefix index?8
34.7 How do you compute top-K per prefix?9
34.8 How do suggestions follow trends?10
34.9 How do you cache suggestions?11
34.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab34. Design Search Autocomplete (Typeahead)
The interview prompt
3 min read+10 XP
This chapter is a full interview round, played out step by step. The interviewer's lines are in quotes. At each step you'll see what a strong candidate says, the pushback the interviewer throws, and how to answer it. At the end, grade yourself with the rubric.
How to use this chapter
- Read only the prompt below. Then stop.
- Set a 45-minute timer and do the whole round yourself, on paper or a whiteboard, out loud. Use the framework from Chapter 1: READ, then Draw, Dive, Defend.
- Then read the walkthrough and compare. Score yourself with the rubric at the end.
Chapter 19 covered tries and search; Chapter 20 covered counting and top-K. This round puts them under a very tight latency budget: every keystroke is a request.
The prompt
"Design the search box suggestions for our bookstore. As the user types, show the top 5 suggested searches."
Stop here. Start your timer.