How to Design a News Feed Ranking System
Learn how to design a news feed ranker: candidate generation, feature scoring, re-ranking, and latency trade-offs at scale.
Expected Interview Answer
A news feed ranking system fetches a large candidate set of recent posts from people and pages a user follows, scores each candidate with a machine-learned model predicting engagement or relevance, then orders and paginates the ranked list, refreshing scores as new signals arrive.
The pipeline splits into candidate generation (pull recent posts from a fan-out write cache or fan-out-on-read query across followed authors, capped to a few thousand candidates), feature extraction (author affinity, post recency, content type, historical engagement, viewer-specific signals), and scoring (a gradient-boosted tree or neural ranker predicts probability of like, comment, share, or watch-time). Posts are then re-ranked with diversity and business rules โ deduplicating similar content, injecting ads, downranking clickbait, and respecting user mute/block preferences. Because relevance decays quickly, the system blends near-real-time signals (this post is trending now) with slower-moving ones (this author usually gets high engagement from this viewer), and it must serve p99 latency under roughly 200ms even though ranking millions of candidates per second across users.
- Surfaces the most relevant content first instead of pure reverse-chronological order
- Blends real-time trending signals with stable long-term affinity for a balanced feed
- Separates candidate generation from scoring so each stage can scale independently
- Supports business rules (ads, diversity, safety) as a re-ranking layer without retraining the core model
AI Mentor Explanation
A news feed ranker is like a highlights producer picking which deliveries from a full day of cricket to show a viewer first. The producer pulls a wide candidate pool of every wicket, boundary and near-miss (candidate generation), scores each clip by how exciting and relevant it is to that specific viewer's favorite team (scoring), then orders the reel so the most compelling moments play first while skipping duplicate replays of the same wicket. A viewer who only follows spin bowling gets those deliveries weighted higher than an unrelated fast-bowling clip. That two-stage pull-then-score-then-order process is exactly how a feed ranking system builds a personalized timeline.
Step-by-Step Explanation
Step 1
Generate candidates
Pull a bounded set (thousands) of recent posts from followed authors via fan-out-on-write cache or fan-out-on-read query.
Step 2
Extract features
Compute author affinity, recency, content type, and viewer-specific engagement history for each candidate.
Step 3
Score with the ranking model
A learned model predicts engagement probability (like, comment, share, watch-time) per candidate.
Step 4
Re-rank and paginate
Apply diversity, ad injection, and safety rules to the scored list, then serve pages with sub-200ms p99 latency.
What Interviewer Expects
- Separates candidate generation from scoring as two distinct, independently scalable stages
- Names concrete features and a plausible model type (GBDT or learned ranker)
- Discusses fan-out-on-write vs fan-out-on-read trade-offs for building the candidate pool
- Mentions re-ranking for diversity, ads, and safety on top of the raw model score
Common Mistakes
- Describing only reverse-chronological sorting instead of a learned ranking model
- Ignoring the candidate generation stage and assuming all posts are scored
- Not addressing latency constraints at scale (millions of feed requests per second)
- Forgetting freshness decay or over-indexing purely on historical affinity
Best Answer (HR Friendly)
โA news feed ranker first gathers a pool of recent posts from people you follow, then uses a model that predicts how likely you are to engage with each one based on your past behavior, and finally orders the feed so the most relevant posts show up first. It constantly balances what is trending right now with what you have historically cared about.โ
Code Example
def rank_feed(user_id, candidates, model):
scored = []
for post in candidates:
features = extract_features(user_id, post)
score = model.predict_engagement(features)
scored.append((post, score))
scored.sort(key=lambda item: item[1], reverse=True)
ranked = apply_diversity_and_safety_rules(scored)
return paginate(ranked, page_size=20)
def extract_features(user_id, post):
return {
"author_affinity": affinity_score(user_id, post.author_id),
"recency_hours": hours_since(post.created_at),
"content_type": post.content_type,
"historical_ctr": historical_click_rate(user_id, post.author_id),
}Follow-up Questions
- How would you handle fan-out for a user who follows millions of accounts?
- How do you prevent the feed from becoming an engagement-maximizing filter bubble?
- How would you A/B test a new ranking model safely against production traffic?
- How do you keep ranking fresh when engagement signals arrive seconds after publish?
MCQ Practice
1. What is the purpose of the candidate generation stage in a feed ranker?
Candidate generation reduces the search space to a manageable set so the more expensive scoring model only runs on relevant posts.
2. Why do feed rankers typically use a learned model instead of pure recency sorting?
A scoring model captures personalized relevance signals that plain chronological order ignores entirely.
3. What is the role of re-ranking after the model produces raw scores?
Re-ranking layers business logic and content policy on top of the model score without requiring retraining.
Flash Cards
Two main stages of feed ranking? โ Candidate generation (narrow the pool) and scoring (rank by predicted engagement).
Why re-rank after scoring? โ To apply diversity, ads, and safety rules on top of the raw model output.
Fan-out-on-write vs fan-out-on-read? โ Precompute per-follower feeds on post creation vs query followed authors at read time.
Typical latency target for feed serving? โ Roughly sub-200ms p99 despite scoring thousands of candidates per request.