P99 0 ms* autocomplete for 240M domain names

220 points · 85 comments on HN · read original →

Points and comments are a snapshot, not live.

An autocomplete API achieves p99 0 ms latency for 240M domains by prefetching suggestions on keydown.

The author built an autocomplete for Wirewiki.com that covers 240 million domain names using a two-tier approach: an in-memory trie for the top 1 million popular domains (Tranco list) and an SSD-backed memory-mapped block index for the rest (CZDS zone files). By firing a prefetch request on keydown that returns suggestions for the typed character plus every possible next character, results are often ready before the user releases the key. Load tests show the API responds in 2 ms at p50 and under 16 ms at p99 up to 6,400 req/s. Network latency from Cloudflare adds 100-200 ms for distant users, preventing true global 0 ms.

What commenters are saying

Commenters split on the author's latency definition: some argued perceived latency starts at keydown, not keyup, and that displaying on keyup adds delay. Others defended the approach as valid for UX. Several pointed out the autocomplete suggests non-existent domains by appending TLDs when no match is found, which confused users expecting only registered domains. A commenter from Australia noted the approach doesn't feel fast due to high latency. Some suggested using CDN storage of trie nodes to reduce network hops, but the author noted R2 caching doesn't distribute globally.