Serving '0 ms' autocomplete across 240M domains by racing the keystroke
The developer behind Wirewiki, a DNS and internet-infrastructure inspection tool, wanted autocomplete that feels instantaneous. The trick behind the headline number is timing, not raw speed: suggestions are prefetched on keyDown and rendered on keyUp, so the request has the full duration of the second keystroke plus the inter-key gap to complete. Measured against real typing, that budget works out to about 121 ms at p99. If results land before the key is released, perceived latency is effectively zero — hence ‘p99 0 ms,’ asterisk included.
The backend is split into a head and a tail. The most popular million domains (from the Tranco list) live in an in-memory prefix trie with the top eight suggestions precomputed for every prefix, so a lookup is just a short pointer walk. The remaining ~240M names from ICANN’s CZDS zone files are delta-compressed into fixed 256-name blocks on SSD, memory-mapped, and indexed by a 27 MB in-memory directory; a query binary-searches the directory then scans a single block, with hot pages cached by the OS. Both structures are effectively O(1) given bounded query length and domain count. An LLM-generated stress test of 720k keystroke queries showed most requests answered in about 2 ms, and 15 ms at p99 even at 1.6k req/s through Nginx.
The honest caveat is geography. The API is fast enough that network round-trip time dominates, and with a single server in Europe, US traffic adds 100–200 ms — enough to blow the p99 budget. Geo-distributed servers with load balancing would restore the ‘0 ms’ experience globally, but the author judges the niche too small to justify the effort or a paid product, unless demand proves otherwise. The piece is a clean case study in exploiting human input timing and cache locality rather than chasing microseconds.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.