31/35
Part 7 of 7 · Follow-upsLearn

For a million items, build each prefix's best k offline and serve it from a key-value store

A prep site's guide for Netflix machine learning engineers lists type-ahead suggestions for titles as a design question (1 source).

At that scale, ranking per keystroke from a trie in one process isn't the design. Build each prefix's best k offline, keep them in a key-value store keyed by the prefix, and make each keystroke one lookup.

For the practice problem's fragments, a million names would need about L²/2 nodes each. So index fragments of one fixed length, such as every fragment of 3 letters, and check only the candidates they point to.