Bird
Raised Fist0

Learning to Rank - Pointwise, Pairwise, Listwise Approaches

SYSTEM-DESIGNhardInterview freq: high
Choose your preparation mode6 modes available
🤖
Learning to Rank - Pointwise, Pairwise, Listwise Approaches
Designing robust ranking systems using pointwise, pairwise, and listwise methods.
system-designhardFreq: highRanking & Retrieval
Prerequisites:Ranking Metrics - NDCG, MAP, MRRGradient Boosting
🎯
Problem Framing

Maximize user engagement by improving the relevance of ranked search results.

Optimize the ranking of items to maximize NDCG@10, focusing on the top results.

  • P99 latency < 100ms for ranking results
  • High throughput of 1000 QPS
  • Cold start for new items
  • Limited labeled data for new queries
  • Compliance with data privacy regulations
  • What is the current baseline performance in terms of NDCG?
  • How frequently do new items get added to the system?
  • What is the expected scale of user queries per day?
  • Are there any specific user segments we should prioritize?
  • What is the acceptable trade-off between latency and accuracy?
Out of Scope
✗ Backend infrastructure scaling
✗ User interface design
✗ Non-ranking related personalization features
📊
Offline Metrics
NDCG@10 because it emphasizes the importance of ranking the most relevant items at the top.
MAP (Mean Average Precision) to evaluate the precision of the ranking across all queries.
📈
Online Metrics
CTR (Click-Through Rate) to measure user engagement with the ranked results.
Revenue per session as a proxy for the business impact of improved ranking.
⚖️
Trade-offs

When offline metrics like NDCG improve but CTR decreases, it may indicate a mismatch between offline relevance and user preferences in production.

💼
Business Metric

Overall increase in user engagement and revenue per session.

🗄️
Data Sources
  • User interaction logs (clicks, impressions) - real-time
  • Item metadata (title, description, category) - updated daily
  • Query logs - real-time
  • User profiles (preferences, history) - updated daily
🏷️
Data Properties

Implicit feedback from user clicks and skips, as explicit labels are scarce.

Approximately 10 million rows/day, 500 GB/month

Features should be updated in real-time to reflect the latest user interactions.

⚠️
Data Challenges
  • Sparse labels due to low click-through rates
  • Position bias where items at the top are clicked more often regardless of relevance
  • Cold start for new items with no interaction history
  • Survivorship bias from only considering clicked items
🔧
Key Features
feat
feat
feat
feat
feat
⚡
Feature Engineering Notes

User-item interaction history needs real-time computation, while item popularity can be pre-computed.

Required

🐍
Feature Snippet
Python
def compute_item_popularity(item_id, interaction_logs):
    return interaction_logs[item_id].count() / len(interaction_logs)
🤖
Model Selection

Logistic regression using basic features like item popularity and query length.

LambdaMART for its ability to directly optimize ranking metrics like NDCG.

LambdaMART is well-suited for optimizing listwise ranking metrics and handles large feature spaces efficiently.
✗
Alternatives Rejected
Pointwise regression models were rejected due to their inability to capture pairwise preferences.
Pairwise RankNet was considered but rejected due to higher complexity in training and less direct optimization of listwise metrics.
🏋️
Training Strategy

Offline training with periodic updates to incorporate new data and user interactions.

🚀
Serving Infrastructure
LatencyP99 < 100ms end-to-end for ranking results.
ThroughputTarget of 1000 QPS.
ArchitectureTwo-stage architecture with initial retrieval followed by detailed ranking to balance speed and accuracy.
CachingCache popular queries with a TTL of 5 minutes to reduce load and latency.
FallbackUse a rule-based system to rank items based on popularity if the model is unavailable.
📡
Data Drift Signals
Shift in query distribution
Change in item metadata distribution
Variation in user interaction patterns
📉
Model Drift Signals
Decrease in NDCG over time
Drop in CTR
Shift in prediction score distribution
🔔
Alerting & Retraining

Retrain when NDCG drops by more than 5% over a month.

Page on-call engineer if CTR drops by more than 10% in a week, log all prediction errors, and auto-recover by switching to cached results.

🎯
Interview Angles
  • How to handle cold start for new items in a ranking system?
  • What are the trade-offs between pointwise, pairwise, and listwise approaches?
  • How to ensure real-time feature updates without compromising latency?
⚠️
Common Mistakes
📌
Key Decisions
  • Choosing LambdaMART for its listwise optimization capabilities.
  • Implementing a two-stage architecture to balance speed and accuracy.
  • Designing a robust caching strategy to handle high QPS.

Practice

(1/5)
1. Which metric is most appropriate for evaluating the diversity of a recommendation feed?
easy
A. Precision
B. Recall
C. Diversity score
D. F1-score

Solution

  1. Step 1: Understand each metric's focus

    Precision and recall focus on relevance, while diversity score measures content variety.
  2. Step 2: Eliminate wrong options

    Precision (A), recall (B), and F1-score (D) do not measure diversity. They focus on relevance and balance between precision and recall.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Diversity score measures content variety [OK]
Hint: Diversity score measures content variety [OK]
Common Mistakes:
2. In the context of a 'People You May Know' feature using graph-based link prediction, which algorithm is most suitable for predicting new connections based on node similarity?
easy
A. Node2Vec
B. Collaborative Filtering
C. K-Means Clustering
D. Decision Trees

Solution

  1. Step 1: Identify the task.

    The task is to predict new connections based on node similarity in a graph.
  2. Step 2: Evaluate options.

    K-Means Clustering (A) is for clustering, not link prediction. Collaborative Filtering (B) is for recommendation systems, not graph-based predictions. Decision Trees (D) are for classification/regression, not graph-based link prediction. Node2Vec (C) is designed for learning node embeddings in graphs, making it suitable for link prediction.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Node2Vec for graph embeddings. [OK]
Hint: Node2Vec is for graph embeddings. [OK]
Common Mistakes:
3. In the context of semantic search, which component is responsible for encoding both queries and documents into a shared vector space?
easy
A. Bi-Encoder
B. Cross-Encoder
C. Dense Retriever
D. Sparse Retriever

Solution

  1. Step 1: Identify the role of each component

    Bi-Encoders encode both queries and documents into a shared vector space for efficient retrieval.
  2. Step 2: Eliminate wrong options

    Cross-Encoders evaluate query-document pairs directly, Dense Retrievers use encoded vectors, Sparse Retrievers use traditional methods.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Bi-Encoder = shared vector space [check]
Hint: Bi-Encoder = shared vector space [check]
Common Mistakes:
4. When designing an intent classification system, should you prioritize using a deep learning model or a simpler model like logistic regression?
medium
A. Always use deep learning for better accuracy
B. Use deep learning if you have a large labeled dataset
C. Use logistic regression for faster training times
D. Use logistic regression if interpretability is crucial

Solution

  1. Step 1: Consider dataset size and complexity.

    Deep learning models require large datasets to perform well, while simpler models can suffice for smaller datasets.
  2. Step 2: Evaluate the trade-offs.

    Always use deep learning for better accuracy: Deep learning isn't always better, especially with small datasets. Use logistic regression for faster training times: Logistic regression is faster but may not capture complex patterns. Use logistic regression if interpretability is crucial: Logistic regression is interpretable but may lack accuracy on complex tasks. Use deep learning if you have a large labeled dataset: Deep learning is suitable for large datasets where complex patterns exist.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Deep learning needs large datasets. [OK]
Hint: Deep learning needs large datasets. [OK]
Common Mistakes:
5. In a search ranking system, when should you prefer a learning-to-rank model over a traditional BM25 algorithm?
medium
A. When you have a small dataset
B. When interpretability is crucial
C. When computational resources are limited
D. When you have rich user interaction data

Solution

  1. Step 1: Assess the data and resource context

    Learning-to-rank models excel with rich interaction data.
  2. Step 2: Evaluate the constraints

    BM25 is better for small datasets, interpretability, and limited resources.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Use learning-to-rank with rich interaction data. [OK]
Hint: Use learning-to-rank with rich interaction data. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard