Lesson 5 of 15
34. Design Search Autocomplete (Typeahead)

34.4 What do we store?

3 min read+10 XP
prefix_suggestions (serving store: in-memory KV / Redis, sharded by prefix) key: "dat" value: ["data science", "database internals", ...] (top 5, already ranked) version: 2026-10-08T06:00 (which build produced it) query_counts (offline: warehouse / batch storage) query, day, count trending_counts (streaming: decayed counts for the last few hours) query, decayed_count, updated_at

Interviewer pushback:

  • "Why store the top 5 for every prefix instead of a trie you walk?" → Walking a subtree to find the top 5 at request time is slow for short prefixes, which have the biggest subtrees and the most traffic. Storing the answer per prefix makes every request a single key lookup (34.6).

Memory code: "The prefix is the key; the answer is already sorted."