Back to KB
Difficulty
Intermediate
Read Time
9 min

Candidate Generation at Scale for Large Catalogs

By Codcompass TeamΒ·Β·9 min read

Engineering Sub-50ms Retrieval Pipelines for Billion-Scale Inventories

Current Situation Analysis

In personalized systems, candidate generation is the hard constraint that dictates the ceiling for all downstream ranking. If the retrieval layer fails to surface a high-recall, diverse, and temporally relevant superset, the ranking model cannot compensate. The industry pain point is not algorithmic accuracy; it is operational latency at scale. Engineering teams routinely struggle to maintain sub-50ms p99 latency while serving catalogs exceeding ten million items, leading to stale recommendations, head-item bias, and degraded long-tail coverage.

This problem is frequently misunderstood because teams optimize for offline metrics like AUC or LogLoss during model training, treating retrieval as a secondary concern. The result is a system that looks excellent in a notebook but collapses under production traffic. The tension is structural: increasing the candidate pool size improves recall but linearly degrades latency and memory pressure. Conversely, aggressive compression and pruning restore latency but often destroy tail-item recall, which is critical for user retention and catalog diversity.

Data from production deployments indicates that monolithic index architectures frequently fail to meet SLAs when QPS spikes or catalog size grows. The failure mode is rarely the ANN algorithm itself; it is the lack of sharding, poor cache invalidation strategies, and the inability to balance offline breadth with online freshness. Successful systems treat retrieval as a distributed engineering problem, where index topology, update cadence, and cascade design are as critical as the embedding model.

WOW Moment: Key Findings

The most significant lever for improving retrieval performance is not switching ANN libraries, but restructuring the index topology and query path. A hybrid cascade approach, combined with sharding by business dimension, consistently outperforms brute-force scaling of a single high-recall index.

The table below compares three architectural patterns for a catalog of 50M items with a target p99 latency of 50ms. The metrics reflect production observations where tail recall is measured as the retrieval rate of items in the bottom 50% of popularity.

Architecture Patternp99 Latency (ms)Tail Recall (Bottom 50%)Memory FootprintUpdate Freshness
Monolithic HNSW6284%High (RAM-bound)Slow (Full rebuild)
Sharded IVF+PQ2868%Low (Compressed)Fast (Per-shard)
Hybrid Cascade3481%MediumReal-time (Hot/Cold)

Why this matters: The Hybrid Cascade demonstrates that you do not need to sacrifice tail recall for latency. By filtering hard constraints early and using a "hot" index for fresh items alongside a compressed "cold" index for breadth, you achieve near-monolithic recall at sharded latency costs. This pattern enables systems to serve diverse recommendations without blowing the latency budget, directly impacting user engagement metrics that depend on long-tail discovery.

Core Solution

Building a production-grade retrieval pipeline requires decoupling the embedding generation from the serving topology and implementing a latency-first cascade. The following steps outline the implementation using a TypeScript-based service architecture, which emphasizes type safety and modular index management.

1. Embedding Strategy and Normalization

The foundation is a two-tower (dual-encoder) model that maps user context and items into a shared vector space. Embedding dimensionality should be calibrated against index size and quantization loss. Dimensions between 64 and 256 are optimal for most production workloads; higher dimensions increase index size and degrade product quantization (PQ) effectiveness without proportional recall gains.

Normalization must be consistent between training and serving. If

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back