Zero-Millisecond Autocomplete for 240 Million Domains: Core Technologies and Engineering Practices

Engineering a near-0ms autocomplete system for 240 million domains with Trie, FST, and in-memory techniques.
This article dissects how to achieve p99 near-0ms autocomplete for 240 million domain names. It covers core data structures like Trie prefix trees and Finite State Transducers (FST), full in-memory residence with cache-friendly layouts, Top-K pruning strategies, and engineering trade-offs including memory vs. latency, incremental updates, and edge deployment for real-world production environments.
Introduction: The Ultimate Performance Challenge for 240 Million Domains
In search and autocomplete scenarios, latency is the core metric that determines user experience. Every time a user types a character in a search box, the system needs to return relevant suggestions within milliseconds. When the data scale balloons to 240 million domain name records, compressing p99 latency to near 0 milliseconds becomes an extremely challenging engineering problem.
A recent project circulating in the Reddit tech community claims to have achieved "p99 0ms*" autocomplete for 240 million domains. The asterisk here is crucial—it reveals the technical trade-offs and preconditions behind the performance numbers. This article takes a deep dive into the core concepts and engineering practices behind building such ultra-low-latency autocomplete systems.
What Does p99 Latency Mean, and Why the "0ms*" Asterisk?
The Meaning of p99
p99 (99th percentile latency) means that 99% of all requests have a response time below a certain value. Compared to average latency, p99 better reflects the system's real-world performance under high load or in tail-end scenarios—it's the key metric for measuring "the vast majority of worst-case experiences."
For real-time interactive features like autocomplete, p99 matters even more than the mean. Even if only 1% of requests experience lag, users in high-frequency typing scenarios will notice it repeatedly, directly destroying the sense of fluid input.
The Engineering Value of Percentile Metrics
p99 latency is part of the percentile metrics system used in performance monitoring. Beyond p99, engineers commonly use p50 (median), p95, p999, and other metrics. The value of these metrics lies in their ability to reveal the long-tail effect of performance distributions—in distributed systems, due to factors like network jitter, GC pauses, and cache misses, a small number of requests may have latency far exceeding the average. Google's SRE practices recommend monitoring multiple percentiles simultaneously, because p99 captures 1% of anomalous requests, and that 1% translates to millions of poor experiences across hundreds of millions of daily requests. In contrast, average latency gets pulled down by the large volume of fast requests, masking real user pain points. This is also why cloud providers like AWS and Google Cloud typically commit to p99 rather than average latency in their SLAs.
What's Behind the Asterisk
The "0ms*" claim typically means this number is based on specific measurement conditions. Possible preconditions include:
- Only server-side processing time is measured, excluding network round-trip time (RTT)
- Data is fully loaded into memory, representing an ideal cache-hit scenario
- Benchmark results under specific hardware and load conditions
In other words, "0ms" doesn't mean zero latency in the physical sense. Rather, it means the server-side computation time has been compressed to sub-millisecond levels, rounding to near zero at the measurement precision available. This alone is an exceptional engineering achievement.
Core Data Structures Behind Sub-Millisecond Autocomplete
Trie (Prefix Tree) and Its Variants
Autocomplete is fundamentally about prefix matching. To quickly find all candidates starting with a given prefix among 240 million records, the most classic data structure is the Trie (prefix tree) and its variants.
Basic Principles and Optimization Evolution of the Trie
The Trie (pronounced "try"), also known as a dictionary tree or prefix tree, was proposed by Edward Fredkin in 1960. Its core advantage is that query time complexity is independent of the total data size—lookup complexity is only O(m), where m is the length of the query string. The standard Trie's weakness is high space consumption, as each node needs to store an array of pointers to child nodes (e.g., 26 for letters). Compressed Tries use path compression to merge consecutive single-child paths into a single edge, significantly reducing the number of nodes. Radix Trees take this further, allowing each edge to store string fragments rather than single characters. In the domain name context, common patterns like '.com' and 'www.' get heavily reused, making compression particularly effective. In practice, engineers also combine character encoding optimizations (e.g., using integers instead of characters) and memory pool management to further boost performance.
For massive datasets, engineering implementations often adopt more compact forms:
- Compressed Trie (Radix Tree / PATRICIA Trie): Merges paths with only a single child node, dramatically reducing memory usage and traversal depth
- FST (Finite State Transducer): Widely used in search engines like Lucene, this stores massive term sets with minimal memory overhead while supporting prefix lookups
- Double-Array Trie: Represents the Trie as arrays, offering cache-friendly access patterns and fast query speeds
Engineering Implementation and Advantages of FST
The Finite State Transducer is the core technology behind Lucene's high-performance Term Dictionary. FST can store not just keys but also associated output values, enabling simultaneous prefix matching and weight retrieval. Compared to a Trie, FST shares both common prefixes and suffixes while minimizing state transitions, compressing memory usage to the extreme—Lucene's benchmarks show that FST can save over 90% of memory compared to a HashMap. FST construction requires sorting the input data, which is a one-time offline cost, but yields near-perfect space efficiency and query performance. In Elasticsearch, FST is used to store the inverted index's term dictionary, ensuring that term lookups maintain millisecond-level response times even when facing billions of documents. FST's limitation is that it doesn't support dynamic updates, which is why segmented indexing and periodic rebuild strategies are necessary.
For domain name data, which exhibits distinct character distribution patterns, prefix tree compression ratios are often remarkably good.
Full In-Memory Residence and Memory Layout Optimization
The most critical prerequisite for achieving 0ms-level latency is eliminating all disk I/O. With proper encoding, 240 million domain names can be compressed to just a few GB and kept resident in memory.
Key optimization techniques include:
- Compact data encoding: Domain deduplication, separating common suffixes (such as .com/.net) into shared storage
- Cache line alignment: Keeping hot data within the same CPU cache line to minimize cache misses
- Reducing pointer chasing: Using array-based structures instead of scattered heap objects to improve memory locality
CPU Cache Hierarchy and Performance Optimization Principles
Modern CPUs typically have three levels of cache: L1, L2, and L3. L1 is the fastest (approximately 1ns access latency) but smallest (32-64KB), L2 is slightly slower (approximately 3-10ns) but larger (256KB-1MB), and L3 is the slowest (approximately 20-40ns) but can range from several MB to tens of MB. By comparison, accessing main memory takes approximately 100ns, and disk access is on the order of milliseconds. A cache line is the basic unit of CPU cache, typically 64 bytes. When a program accesses a memory address, the CPU loads the entire cache line—if adjacent data will also be accessed (spatial locality), that load pays off handsomely. False sharing is a performance killer in multi-core environments—when multiple threads modify different variables within the same cache line, it causes frequent cache line invalidation and synchronization across CPU cores. For high-frequency data structures like Tries, designing the memory layout with contiguous array storage and aligning to cache line boundaries can reduce cache miss rates by over 50%, directly translating to halved query latency.
When all queries complete within L2/L3 cache and main memory, a single prefix lookup takes nanoseconds to microseconds, which at the p99 level approaches zero.
Candidate Ranking and Top-K Result Pruning
Finding prefix matches is only the first step—autocomplete also needs to rank results by relevance and return Top-K results. To avoid the latency of exhaustive traversal, common approaches include:
- Pre-storing weight information at Trie nodes (such as domain popularity or access frequency)
- Using Top-K pruning strategies that terminate early once enough high-quality candidates are collected
- Pre-computing and caching ranked results at high-frequency prefix nodes
These optimizations ensure that even when a prefix matches millions of candidates, the time to return results remains stable and predictable.
Engineering Trade-offs and Production Considerations
Memory Usage vs. Latency
The cost of a fully in-memory approach is obvious: it requires enough RAM, and the service needs to load and build the index at startup. For 240 million records, this means several to a dozen GB of memory usage, plus potentially tens of seconds of cold start time.
Engineering Practices with Memory-Mapped Files
This is why many systems introduce memory-mapped files (mmap), allowing the operating system to page index data into memory on demand, striking a balance between startup speed and memory usage. Memory-mapped files (mmap) are an OS mechanism that maps file contents directly into a process's address space. Through mmap, programs can access files as if they were memory arrays, while actual disk I/O is performed on demand by the OS (triggered by page faults). This lazy loading strategy is extremely valuable when dealing with very large indexes—the service doesn't need to wait for several GB of data to fully load at startup; instead, the OS progressively pages in hot data based on access patterns. Linux's page cache intelligently keeps frequently accessed file pages in memory while allowing cold data to be swapped out. Storage engines like Lucene and RocksDB make extensive use of mmap. However, mmap has its costs: page-in and page-out operations can introduce unpredictable latency spikes, and under memory pressure, the OS may force disk flushes causing a performance cliff. Therefore, production environments need careful tuning of kernel parameters like min_free_kbytes and monitoring of page fault metrics to find the right balance between startup speed, memory usage, and stability.
Incremental Updates and Data Freshness
Domain data is not static—new domain registrations and expirations need to be reflected in autocomplete results. However, highly optimized static index structures (like FST) typically don't support in-place updates.
The typical solution is read-write separation with segmented building: data is split into "solidified large index segments" and "small incremental index segments," with query results merged at query time and full indexes periodically rebuilt in the background. This sacrifices some real-time freshness to preserve peak query-side performance.
Network Latency Is the Real Bottleneck
It's worth emphasizing that even with 0ms on the server side, the latency users actually perceive is still governed by network round trips.
Edge Computing and CDN Acceleration Principles
This is why such systems in production environments are typically paired with edge deployment, CDN, client-side prefetching, and local caching to also compress the latency introduced by physical distance. Edge computing refers to deploying compute resources at network edge nodes close to users, rather than concentrating them in remote data centers. For latency-sensitive services like autocomplete, edge deployment can shorten physical distance from thousands of kilometers to tens of kilometers, reducing network RTT from 100-200ms to 10-20ms. CDNs (Content Delivery Networks) traditionally handle static resource distribution, but modern CDNs like Cloudflare Workers and AWS Lambda@Edge now support edge computing capabilities, running lightweight business logic. A typical architecture for edge autocomplete is: pre-compute completion results for high-frequency prefixes and push them to global edge nodes, where user requests are served by the nearest node; low-frequency or new queries fall back to the central cluster. Under this architecture, over 90% of requests can be served within the user's 50ms latency radius, while the remaining 10% don't affect the overall p99 metric due to their low hit rate. The challenge with edge deployment lies in data consistency and update latency—efficient cache invalidation and incremental synchronization mechanisms are essential.
Summary: A Methodology for Massive-Scale Autocomplete
Achieving "p99 0ms*" autocomplete for 240 million domains is a combined victory of data structures, memory engineering, and system design. The core takeaways are:
- Choosing the right data structure is foundational: Prefix-friendly structures like Tries and FSTs are the cornerstone of massive-scale autocomplete
- Eliminating disk I/O is the prerequisite for peak performance: Full in-memory residence combined with cache-friendly layouts pushes latency to hardware limits
- Performance numbers require understanding the preconditions: That "*" reminds us that every benchmark has its applicable boundaries
For engineers building search autocomplete or recommendation systems, this case study demonstrates a complete methodology for pursuing extreme latency at extreme scale. True high performance rarely comes from a single magic trick—it stems from a deep understanding of data characteristics and continuous refinement at every layer of the stack.
Related articles

OpenAI Launches ChatGPT Images 2.5: A New Breakthrough in AI Image Generation
OpenAI launches ChatGPT Images 2.5, supporting sketch, reference image, and text multimodal input, significantly enhancing personalized image generation and refinement.

Devin's Parent Company Cognition Raises $2B, Valuation Soars to $48B
Cognition closes $2B funding round at $48B valuation, joining the ranks of highest-valued AI startups. Deep dive into Devin's technical positioning, capital logic, and competitive landscape.

AgentWall: A Security Interception Solution for LangChain Tool Calls
AgentWall provides pre-execution security interception for LangChain Agents through three-tier risk classification, human approval, and rollback hooks, addressing architectural risks of unchecked autonomous tool execution.