Two-Tower Model for Recommendation Service having a Very Large Catalog

CK CK 3776 
Created at  
253 0 0

The Two-Tower model (also called a dual-encoder) is the workhorse of large-scale candidate generation (retrieval). It encodes users and items into the same embedding space using two separate neural networks — a user tower and an item tower — and measures affinity by a simple similarity (dot product or cosine) between the two output vectors.

The decisive property: because the towers are independent and only meet at the final similarity, item embeddings can be precomputed offline and indexed for approximate nearest-neighbor (ANN) search. At request time you encode just the user, then retrieve the top-K items from millions or billions in milliseconds. This is what makes retrieval at internet scale feasible.

Two-Tower Model for Recommendation Service having a Very Large Catalog

 

How It Works (The Math)

Each tower is a neural network mapping raw features to a d-dimensional embedding:

u = f_user(x_user; θ_u), v = f_item(x_item; θ_i)

Affinity is their inner product (optionally normalized):

s(u, i) = u · v

Training as in-batch softmax

The model is trained as a retrieval/classification problem: given a user, the positive item should score higher than all others. Using in-batch negatives, every other item in the mini-batch serves as a negative for a given user, which is extremely efficient:

L = − Σ_{(u,i) ∈ batch} log [ exp(s(u,i)) / Σ_{j ∈ batch} exp(s(u,j)) ]

Sampling-bias correction

In-batch negatives are drawn by popularity, biasing the softmax toward popular items. The standard fix (Yi et al., 2019) subtracts a logQ correction using the estimated sampling probability p_j:

s'(u, j) = s(u, j) − log p_j

This logQ-corrected in-batch softmax is the canonical recipe for production two-tower retrieval.



 

Requirements

  • User and item feature pipelines. Unlike pure ID models, towers typically ingest rich features, which is what gives them cold-start capability for new items.
  • A training stack supporting large embedding tables and in-batch (or mixed) negative sampling.
  • An ANN (Approximate Nearest Neighbor) index — e.g., ScaNN (Scalable Nearest Neighbors), FAISS (Facebook AI Similarity Search), HNSW (Hierarchical Navigable Small World) — over item embeddings for serving, plus a pipeline to refresh item embeddings as the item tower retrains.
  • A real-time user-feature service to build the query vector at request time.
  • Frequency/sampling-probability estimation for the logQ correction.



 

Simplified Architecture

Two-Tower Model for Recommendation Service having a Very Large Catalog


 

Reference Architecture

Two-Tower Model for Recommendation Service having a Very Large Catalog


 

Reference Architecture (with Technology Stack)

The same flow on concrete tooling — towers trained on GPU with TensorFlow/PyTorch, batch item-tower inference via Spark/Beam, a Milvus/ScaNN vector index, and the user tower served live on Triton.

Two-Tower Model for Recommendation Service having a Very Large Catalog


 

Signals & Features

The user tower consumes interaction history (often pooled or sequence-encoded), demographics, and context (device, time, location). The item tower consumes content features (text/image embeddings, category, creator, age) alongside the item ID. Feeding content features into the item tower is precisely what lets the model embed brand-new items sensibly before they have any interactions — its cold-start advantage over ID-only matrix factorization.



 

Training & Serving Considerations

The architecture deliberately keeps the towers decoupled so item embeddings are query-independent and cacheable. This is also its main limitation: because users and items only interact via a single dot product, the model cannot learn fine-grained cross-features — that work is deferred to the downstream ranking model. The serving loop has two cadences: frequent user-tower inference at request time, and periodic batch re-embedding of the catalog plus ANN index rebuild. Embedding “staleness” between rebuilds is a real operational concern for fast-moving catalogs.



 

Evaluation

Retrieval quality is measured with recall@k (did the relevant item appear in the retrieved top-K?) and the contribution to downstream end-to-end metrics after ranking. Because retrieval is the funnel’s top, its job is high recall, not precise ordering — over-optimizing retrieval precision is a common mistake. Monitor index freshness and the share of impressions sourced from the two-tower retriever.



 

Strengths & Weaknesses

Strengths: massive-scale retrieval via precomputed item embeddings + ANN; handles item cold-start through content features; efficient in-batch-negative training; the de facto standard for the candidate-generation stage.

Weaknesses: the decoupled dot product cannot model user–item cross-features, capping accuracy (hence a separate ranking stage); sampling/popularity bias must be corrected; index staleness between rebuilds; tuning negatives and the logQ correction is nontrivial.



 

When to Use It

Use the two-tower model whenever you must retrieve a small relevant candidate set from a very large catalog under tight latency — the first stage of nearly every modern feed and search-ranking system (YouTube, Google Play, large e-commerce). Pair it with a heavier ranking model (Wide & Deep, DeepFM, or a sequence/cross model) that re-scores the retrieved candidates with full feature interactions.

Tags Candidate Generation Cold Start Problem Deep Learning Dual Encoder Item Embeddings Machine Learning Recommendation Architecture Recommendation System Scalable Retrieval Two-Tower Model Vector Search Facebook X
Comments 0
Similar posts
  1. Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce
    239
  2. Neural Collaborative Filtering (NCF) for Recommendation Service
    234
  3. Hybrid Methods for Recommendation Service
    211
  4. Wide & Deep / DeepFM for Recommendation Service (aka Ranking Service)
    245
  5. Model-Based CF: Matrix Factorization for Recommendation Service
    176
  6. Memory-Based Collaborative Filtering for Recommendation Service
    185
  7. Content-Based Filtering for Recommendation Service (aka User-based Model)
    187
  8. Common Recommendation Service Architecture
    523
  9. Harnessing the Power of Random Forest Algorithm in Python
    656
  10. Mastering Model Persistence: Saving and Loading Trained Machine Learning Models in Python
    1,152
  11. YouTube's Recommendation System
    257
  12. Reinforcement Learning–Based Methods for CTR Improvement based on Recommendation System
    258
  13. Understanding and Implementing K-Nearest Neighbors (KNN) Algorithm in Python
    629
  14. Forecasting the Weather with PyTorch: A Beginner's Guide to Temperature Prediction
    1,427
  15. Getting Started with PyTorch: A Beginner's Guide to Building Your First Neural Network
    797
  16. Mastering AI: A Beginner's Guide to Python Programming and Beyond
    1,031
  17. Forecasting with Linear Regression and KNN Regression in Python
    919
  18. Vector Databases: From Embeddings to Application
    309
  19. Image Embeddings for Vector Databases
    239
  20. Deep Dive into Vector Databases: Understanding Collections (Not Tables) and Embeddings
    226
  21. Machine Learning Models for Ad Detection from a Video Stream
    184
  22. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    307
  23. TikTok's Recommendation System - Monolith
    284
  24. Milvus & FAISS: Decoding Their ML Synergy
    275
  25. PyTorch example to Forcast Stock Price based on 10 days Dataset
    651
  26. Predicting Buyer Preferences with PyTorch: A Deep Learning Approach
    1,228
  27. Mastering Ad Budget Throttling: Static, PID, and ML Strategies
    315
  28. Ad Impression Forecasting (aka Ad Inventory Forecasting): Architecting for Scale, Speed, and Accuracy
    327
  29. AI-Powered Ad Fraud Detection: Architectural Strategies
    331
  30. Brand Safety: AI-Driven Content Moderation on AWS
    703
  1. The Revenge of the Junior Developer
    2,275
  2. A Complete Guide to LLM Dataset Formats: From Pre-Training to DPO in JSONL
    191
  3. Comparison of ChatGPT, Gemini, and Grok
    549
  4. MLOps Explained: Spark, Flink, and Reference Architecture Deep Dive
    236
  5. AI-based Image Creation based on Bing Image Creator
    978
  6. ChatGPT App (flowGPT) to create images with text
    1,030
  7. TikTok's Recommendation System - Monolith
    284
  8. Things to Know for AI-driven, Multimodal Content Personalization.
    194
  9. Deep Dive into Vector Databases: Understanding Collections (Not Tables) and Embeddings
    226
  10. Image Embeddings for Vector Databases
    239
  11. Vector Databases: From Embeddings to Application
    309
  12. Scaling Vector Search: How to Architect FAISS on AWS EKS and ECS
    155
  13. Reinforcement Learning–Based Methods for CTR Improvement based on Recommendation System
    258
  14. YouTube's Recommendation System
    257
  15. Wide & Deep / DeepFM for Recommendation Service (aka Ranking Service)
    245
  16. Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce
    239
  17. Neural Collaborative Filtering (NCF) for Recommendation Service
    234
  18. Common Recommendation Service Architecture
    523
Recently updated
  1. How do I create animated background for Google Meet?
    18,998
  2. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    192
  3. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    75
  4. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    151
  5. Array of arguments passed to script in PHP
    83
  6. Invalid Auction Storms in Ad Tech
    91
  7. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    194
  8. The Two Clocks of Ad Server Architecture
    61
  9. Frequency Cap Architecture Overview
    505
  10. Collecting Proof-of-Play from 100,000 Screens
    139
  11. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    276
  12. What is RedisVL?
    102
  13. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    218
  14. TPU & GPU Cluster Management Tools
    229
  15. The Concept of Scaffolding in AI Agents
    217
  16. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    568
  17. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    246
  18. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    321
  19. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    196
  20. Machine Learning: Training vs. Ranking
    200
  21. The Continuous Learning Machine: Designing a Loop That Actually Turns
    212
  22. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    188
  23. Designing a Data Curation System Around a Vector Database
    212
  24. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    228
  25. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    646
  26. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    179
  27. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    203
  28. Understanding Data Lineage
    251
  29. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    159
  30. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    229