Designing a User-Generated Game Recommendation System
Machine LearningModel answerLast updated
Architect an end-to-end recommendation backend and ML pipeline for a large platform offering user-created interactive experiences, emphasizing cold-start strategies and multi-task learning.
You are tasked with designing a personalized game discovery engine for a large-scale gaming platform featuring millions of user-generated interactive experiences and tens of millions of daily active players. The engine generates the main "Recommended for You" section on the user's home screen.
Core Requirements
- Objective & Loss Formulation: Define the primary optimization targets. How do you convert complex user engagement behaviors into concrete ML loss functions while avoiding clickbait traps?
- Feature Engineering & Cold-Start Strategy: Detail user, item, context, and cross features. Propose a clear method for handling newly published games (item cold-start) and brand-new players (user cold-start).
- Multi-Stage Architecture: Outline a multi-stage pipeline (Retrieval, Pre-Ranking, Heavy Ranking, Re-Ranking) capable of filtering millions of candidates down to a top-50 feed under low-latency constraints.
- Data Pipeline & Train/Serve Skew: Explain how to build the training dataset, capture labels correctly, handle attribution windows, and avoid temporal data leakage.
- Evaluation Strategy: Define offline evaluation metrics and outline an online A/B testing strategy.
Constraints & Context
- Target Latency: $p_{99} < 180\text{ ms}$ end-to-end.
- Dynamic Content: Thousands of new games are created daily; game popularity can surge or decay rapidly within hours.
- Catalog Heterogeneity: Games vary wildly in genre, style, and session length (e.g., 2-minute casual arcade games vs. 45-minute multi-player RPGs).
Hints
Hint 1
Avoid relying solely on Click-Through Rate (CTR); raw clicks favor misleading thumbnails over long-term retention.
Hint 2
For item cold-start, separate behavioral signals from content signals using modality encoders (text, thumbnail, creator history) and structural dropouts during training.
Hint 3
Log feature snapshots directly at inference time rather than relying on point-in-time offline backfills to guarantee zero train-serve feature skew.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements & System Constraints
Key Metrics & Operational Context
- Scale: $\approx 80\text{M}$ DAU generating $\approx 400\text{M}$ recommendation requests per day (peak traffic $\approx 15,000\text{ QPS}$).
- Catalog Size: $\approx 5\text{M}$ total experiences, with $\approx 500,000$ active titles generating interaction events weekly.
- Latency Budget ($p_{99} \le 180\text{ ms}$):
- Candidate Retrieval (Retrieval Stage): $30\text{ ms}$
- Real-Time Feature Ingestion / Store Lookup: $25\text{ ms}$
- Heavy Multi-Task Ranking: $70\text{ ms}$
- Contextual Re-ranking & Business Rules: $15\text{ ms}$
- Network overhead / Buffer: $40\text{ ms}$
2. Objective & Loss Formulation
Optimizing strictly for Click-Through Rate ($\text{CTR}$) leads to thumbnail clickbait and poor user retention. Instead, we optimize for Long-Term Satisfied Playtime.
+---> p_click (Binary Cross-Entropy)
|
User/Item Features ------->+---> p_qualified_play | click (Binary Cross-Entropy)
|
+---> E[log(play_duration)] | click (MSE Loss)
|
+---> p_return_7d (Binary Cross-Entropy)
Multi-Task Modeling Objectives
We formulate the ranking stage as a Multi-Task Learning (MTL) architecture using Multi-gate Mixture-of-Experts (MMoE) or Shared-Bottom with Task-Specific Heads:
- Click Prediction ($y_{\text{click}} \in {0, 1}$):
- Loss: Binary Cross-Entropy ($\mathcal{L}_{\text{BCE}}$).
- Qualified Play ($y_{\text{qual}} \in {0, 1}$):
- Defined as session duration $> T_{\text{genre}}$, where $T_{\text{genre}}$ is the 30th percentile duration for that specific genre (e.g., 3 minutes for a casual obstacle course, 15 minutes for a strategy game).
- Loss: Binary Cross-Entropy on clicked impressions.
- Session Duration ($y_{\text{dur}} \in \mathbb{R}^+$):
- Predicts $\log(1 + \text{duration_seconds})$.
- Loss: Mean Squared Error ($\mathcal{L}_{\text{MSE}}$) or Huber Loss on clicked impressions.
- 7-Day Revisit ($y_{\text{return}} \in {0, 1}$):
- Predicts whether the user launches the same experience again within 7 days.
- Loss: Binary Cross-Entropy ($\mathcal{L}_{\text{BCE}}$).
Utility Scoring Function
At serving time, output probabilities are combined using a tuned linear-log combination:
$$\text{Score} = p_{\text{click}} \times \left( w_1 \cdot p_{\text{qual}} + w_2 \cdot \log(1 + \hat{E}[\text{duration}]) + w_3 \cdot p_{\text{return}} \right) + w_4 \cdot S_{\text{social}}$$
where $S_{\text{social}}$ represents social affinity signals (e.g., number of friends currently active in that experience). Weights $w_1 \dots w_4$ are tuned online via Pareto optimization or multi-armed bandits.
3. Feature Engineering & Cold-Start Strategy
| Feature Category | Description & Processing Method |
|---|---|
| User Demographics & Context | Age group, locale, client device (mobile/PC/console), connection speed, time-of-day bucket. |
| User Real-Time History | Sequence of last 30 played games (IDs, genres, play durations). Encoded via dynamic sequence pooling / Transformer layers. |
| Item Static & Content | Game title, description text embeddings (Sentence-BERT), thumbnail visual embeddings (ResNet/ViT), age rating, creator historical metrics. |
| Item Streaming Metrics | Exponentially decayed CTR, qualified play rates (1h, 6h, 24h windows), smoothed via Bayesian Priors: $\frac{\text{clicks} + \alpha}{\text{impressions} + \alpha + \beta}$. |
| Cross / Interaction | Categorical cross of (User Favorite Genre $\times$ Candidate Genre), user's historical interaction frequency with the candidate game's creator. |
COLD-START TIERING
New Item Launch ---> [ Content Features Only ] ---> [ Multi-Modal Vector Space ]
|
v
Initial Traffic <--- [ Beta-Prior Smoothing ] <--- [ Freshness Exploration Pool ]
Cold-Start Handling Strategies
Item Cold-Start (New Games)
- Multi-Modal Content Vectors: Train a Two-Tower model where the item tower accepts text, thumbnail images, and creator reputation embeddings. When a game has zero interaction history, its representation relies entirely on this content tower.
- Item ID Dropout: During training, randomly zero out the learned Item ID embedding $15%$ of the time. This forces the downstream model to rely on structural features (content vectors, tags, creator info) rather than memorizing explicit IDs.
- Exploration Bucket: Dedicate $5%$ of recommendation slots on the homepage to a upper confidence bound (UCB) exploration loop for new titles that pass initial quality and safety filters.
User Cold-Start (New Players)
- Context & Onboarding Signals: Use device type, platform, geometric location, and explicit onboarding survey inputs (selected interest tags).
- Popularity Fallbacks: Default to top-performing items broken down by localized cohort (e.g., "Top Trending among New Users in Region X on Mobile").
4. Multi-Stage Pipeline Architecture
To scale candidate filtering from 5 million items to 50 final display items, we implement a four-stage funnel:
[ Catalog: ~5M ]
|
v
[ 1. Candidate Retrieval ] ---> Multi-source retrieval (ANN, Social, Trending) -> ~2,000 items
|
v
[ 2. Pre-Ranking ] ----------> Light MLP / Vector Inner-Product ------------> ~400 items
|
v
[ 3. Heavy Ranking ] --------> MMoE Multi-Task Neural Network --------------> ~400 scored
|
v
[ 4. Re-Ranking & Rules ] --> Diversity (DPP), Safety, Deduplication -------> Final 50 items
1. Candidate Retrieval (Output: ~2,000 items)
Employs multiple parallel candidate sources to maximize recall:
- Two-Tower Neural Retrieval: Dual-encoder computing $\langle U(x), I(y) \rangle$. Nearest neighbor search executed against a vector index (e.g., HNSW or ScaNN).
- Social Graph Retrieval: Selects active experiences where the user's direct friends are currently playing or have played in the past 24 hours.
- Item-to-Item Collaborative Filtering: Selects candidates similar to the user's top 3 most played games over the last 48 hours.
- Exploration & Freshness Source: Top-performing newly published games meeting preliminary engagement thresholds.
2. Pre-Ranking (Output: ~400 items)
A lightweight deep neural network or matrix factorization model that prunes candidate items based on static features and simplified dot-product similarity, cutting down computation before running heavy inference.
3. Heavy Ranking (Output: ~400 scored items)
Runs an MMoE (Multi-gate Mixture-of-Experts) architecture combining cross-features, real-time sequences, and dense user/item interactions to output predictions for $\hat{p}{\text{click}}$, $\hat{p}{\text{qual}}$, $\hat{E}[\text{dur}]$, and $\hat{p}_{\text{return}}$.
4. Re-Ranking & Business Rules (Output: 50 items)
- Diversity Enforcement: Determinantal Point Processes (DPP) or Maximal Marginal Relevance (MMR) applied across game tags to avoid presenting rows dominated by a single genre.
- Creator Deduplication: Cap maximum items from a single developer/creator to 2 per 50-item slate.
- Age Appropriateness & Moderation: Hard filters based on user age bracket and content ratings.
5. Data Pipeline & Train/Serve Skew Control
Serving Time:
[ Request ] ---> [ Log Exact Online Feature Vector ] ---> [ Online Feature Store ]
|
v
Pipeline: [ Event Bus (Kafka) ]
|
v
Labels: [ Joined Stream (Join via request_id) ]
|
v
Training: [ Point-in-Time Accurate Training Dataset ]
Preventing Train/Serve Skew
- Log-on-Serve Pattern: Instead of reconstructing historical feature state offline (which risks temporal data leakage), log the exact feature vector used at the moment of prediction alongside a unique
request_id. - Delayed Label Join: Join impression logs with downstream user activity streams (clicks, game session durations, 7-day revisits) using the
request_id.- Click label: Captured within a 30-minute window.
- Session duration: Updated upon game-exit event.
- 7-day return label: Joined 7 days later; trained on a rolling historical window to avoid label delay bias.
Cross-Validation Strategy
- Time-Based Splitting: Split datasets strictly chronologically (e.g., train on Days $1 \dots N-1$, validate on Day $N$). Never use random $K$-fold cross-validation on user interaction data.
6. Evaluation Strategy
Offline Evaluation Metrics
- Retrieval Stage: Recall@K ($K=100, 500, 2000$), Hit Rate, Mean Reciprocal Rank (MRR).
- Ranking Stage:
- Binary tasks ($\text{click}$, $\text{qual}$, $\text{return}$): Area Under the ROC Curve (AUC) and Group AUC (GAUC) grouped by user. GAUC measures relative ranking quality within individual user sessions:
$$\text{GAUC} = \frac{\sum_{u} w_u \cdot \text{AUC}u}{\sum{u} w_u}$$
- Continuous task ($\text{duration}$): Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE) on positive interactions.
Online A/B Testing Framework
- Primary Metrics:
- D1, D7, and D30 User Retention Rate.
- Mean Qualified Session Playtime per DAU.
- Guardrail Metrics:
- $p_{99}$ Homepage Latency ($< 180\text{ ms}$).
- Long-tail Creator Impression Rate (ensuring non-top-1% creators receive discovery traffic).
- Click-to-Play bounce rate ($< 30\text{-second}$ abandon rate).
Common Pitfalls to Avoid
- Optimizing for Raw CTR: Leads to high click rates followed by immediate exits, harming long-term retention.
- Using Un-viewed Tiles as Hard Negatives: Assigning negative labels to tiles that were retrieved but never scrolled into the user's viewport causes false negative noise. Filter training samples to viewport-visible impressions only.
- Offline Point-in-Time Data Leakage: Computing features like "Game Lifetime CTR" using interaction data logged after the time of the impression. Features must reflect state strictly prior to the request timestamp.