Search Autocomplete (Typeahead) 00:00:01 The second keystroke wins A rider types H, then O, then another letter before the first network reply arrives. Design autocomplete to surface a useful suggestion for the current prefix without letting an old response overwrite a new one. In this example the phone debounces short typing bursts before requesting suggestions for the current prefix. Ask Redis for a ranked answer to this prefix and version. it can save the ranker's work. 100 queries in stored order: home depot, hotels near me, how to tie a tie and more. The client checks that this is still the latest request, reorders with local history and draws. Attach a request generation to each typed prefix. A fast cache hit for yesterday's query is still the wrong answer if the user has already typed something else. 00:00:52 Find a prefix without scanning the dictionary A popular prefix can begin thousands of search phrases. A trie represents shared leading characters once. Walk the path for H, O, W, then ask what has already been prepared at that node. Prefix how. Every query is somewhere below the root. Three characters, three steps. The ten best IDs are already here: how to tie a tie, how to screenshot and others. The list is copied out. No part of the index changed. Precomputed top identifiers exchange update cost and memory for a predictable lookup. Keep details and per-viewer ranking outside that lookup when their refresh requirements differ. 00:01:36 Replace the index without emptying it A new suggestion index has finished building. Publishing it is a deployment problem: replicas must be able to serve a complete old or new version throughout the change. In this illustrative capacity plan a durable stream carries completed search events into a repeatable index-building job. The file becomes version 1234. Its checksum is stored with it. A compact file is faster to load than building from a list of queries. The old copy is freed and replica 2 starts. One of four is done: 25%. Verify the new file, warm a replica, switch the pointer and retain a rollback path. Include the index version in compatible caches so an answer can be traced to its source. 00:02:23 Detect a trend before a full rebuild A tournament begins while the offline index still reflects yesterday. A short-lived overlay can add popular recent phrases without rewriting the entire trie every minute. Someone searches world cup during a match. Flink keeps one-minute windows of distinct people. A person opens an empty box. The client asks for the list. The edge may keep it 30 seconds. The suggest service merges the same list when a typed prefix matches. Bound and expire the overlay, apply eligibility and quality controls, and deduplicate phrases when combining it with the base index. A burst then fades instead of permanently rewriting suggestions. 00:03:05 Rank under a typing deadline A request for suggestions is useful only before the next characters make it obsolete. Compare ranking work with a stored order that is available immediately. 100 candidates arrive for how. Four are shown. For the first candidate the example combines several bounded signals into one ranking score. The coefficients are teaching assumptions, not a universal ranking formula. A lower combined score puts this candidate later in the list even when one individual feature looks promising. At 20 ms the service stops waiting and uses the stored order. A versioned prefix index supplies dependable candidates, the short overlay adds freshness, and the client decides whether the finished result still belongs to what the user typed.