Multi-Stage Ranking Pipeline
Multi-Stage Ranking Pipeline
TikTok's ranking pipeline is a multi-stage funnel that narrows billions of videos down to the 10 shown on screen. Each stage trades accuracy for speed, ensuring the entire process completes in under 200 milliseconds.
Why a funnel?
You cannot run a complex deep learning model on every video in the library. With billions of videos and millions of concurrent users, the computational cost would be impossible. The funnel solves this by progressively filtering candidates through increasingly precise (and expensive) stages.
The four stages
Billions of videos
|
v
Stage 1: Candidate Retrieval (sub-50ms)
- Reduces billions to ~500-1,000 candidates
- Fast, approximate matching
- Uses Two-Tower Neural Network for ANN search
|
v
Stage 2: Early-Stage / Coarse Ranking (sub-30ms)
- Reduces ~500 to ~100-200 candidates
- Lightweight neural network (distilled model)
- Basic features: user-item interactions, simple embeddings
- Goal: high recall, low latency
|
v
Stage 3: Late-Stage / Fine Ranking (sub-80ms)
- Reduces ~200 to ~20-30 candidates
- Heavy deep neural network (hundreds of millions of parameters)
- Complex feature interactions
- Predicts multiple objectives simultaneously
|
v
Stage 4: Re-ranking (sub-40ms)
- Applies diversity, safety, and business rules
- Final selection of ~10 videos
- Ad insertion
|
v
Serve to user
Stage 1: Candidate Retrieval
See Two-Tower Neural Network for the full architecture.
The retrieval stage pulls candidates from multiple sources to ensure diversity:
| Source | Latency | Purpose |
|---|---|---|
| Two-tower ANN search | < 20ms | Interest-based discovery |
| Followee videos | < 10ms | Social graph signal |
| Trending/popular | < 5ms | Popularity baseline |
| Similar-user collaborative filtering | < 20ms | "Users like you also watched" |
| Fresh uploads | < 5ms | Recency signal |
The sub-50ms budget for this stage is critical. ANN search via HNSW indexes makes it possible to search billions of vectors in milliseconds.
Stage 2: Early-Stage Ranking (Coarse)
A lightweight, distilled version of the full ranking model. It uses basic features and็ฎๅ feature crosses to quickly eliminate obviously irrelevant candidates.
The coarse ranking model is a "student" model trained to approximate the "teacher" (full ranking model). It captures 90% of the ranking quality at 10% of the computational cost.
Stage 3: Late-Stage Ranking (Fine)
This is where the heavy computation happens. A deep neural network -- often based on architectures like DeepFM, DCN, or Transformer-based sequence models -- scores each remaining candidate.
Multi-objective prediction
TikTok does not optimize for a single metric. The model predicts multiple probabilities simultaneously using a Multi-Gate Mixture of Experts (MMoE) architecture:
| Objective | What it predicts |
|---|---|
| Completion probability | Will the user watch to the end? |
| Like probability | Will the user tap the heart? |
| Share probability | Will the user send this to someone? |
| Save probability | Will the user bookmark this? |
| Comment probability | Will the user leave a comment? |
| Follow probability | Will the user follow the creator? |
These predictions are combined into a final score using weighted coefficients that reflect the TikTok Signal Hierarchy.
Feature richness
The fine ranking model considers features that the coarse model cannot:
- User features: session history, time-of-day patterns, device type, location
- Video features: visual embeddings, audio characteristics, transcript keywords, caption text
- Cross features: user-video affinity (has the user watched similar content before?)
- Context features: current trending topics, time since upload, creator's recent performance
Stage 4: Re-ranking
The final stage applies rules that the ranking model cannot encode:
Diversity injection
- No two consecutive videos from the same creator
- Maximum N% of feed from the same sound or hashtag
- Ensures the feed doesn't become a monotonous loop of similar content
Freshness adjustment
- Periodically inject new or trending content
- Prevents filter bubbles where users only see content identical to what they've already watched
Policy filters
- Deprioritize (not remove) borderline content
- Age-gate certain categories for users under 18
- Anti-spam and anti-manipulation checks
Ad insertion
- Every N organic videos, insert a paid placement
- Ads are ranked by a separate ad ranking model optimized for advertiser goals
Latency budget breakdown
| Stage | Latency | Model complexity |
|---|---|---|
| Candidate retrieval | < 50ms | Simple (ANN search) |
| Coarse ranking | < 30ms | Lightweight (distilled) |
| Fine ranking | < 80ms | Heavy (full DNN) |
| Re-ranking | < 40ms | Rule-based + lightweight |
| Total | < 200ms |
The pre-ranking optimization
The biggest latency optimization is not architectural but temporal. While the user is watching the current video (say, 3 seconds in), the system is already scoring candidates for what comes next. By the time they swipe, the result is ready. The swipe triggers delivery, not ranking.
This pipelining means the perceived latency is near-zero even though the actual computation takes 150-200ms.
See Real-Time Feedback Loop for the full event pipeline.
See also
- Two-Tower Neural Network - Stage 1 architecture
- TikTok Signal Hierarchy - How objectives are weighted
- Video Completion Rate as Currency - The dominant ranking signal
- Real-Time Feedback Loop - The event pipeline that feeds the ranking model
- Monolith Framework - How the ranking model is trained in real-time
- Why TikTok's Algorithm Feels So Good - Why this funnel creates a "magical" experience