ML System Design

Design: Social Feed Ranking

Ranking posts in a social media feed balancing engagement, relevance, content quality, and creator fairness.

🔴 advanced7 min readsystem-designrecsys
Designing a Social Feed Ranking System orders posts from friends, creators, and advertisers into a personalized timeline. The system must balance multiple objectives (engagement, content quality, user satisfaction) while handling viral content spikes, filter bubbles, and creator ecosystem health.

The Problem

Design a social feed for a platform where users follow friends and creators. Each user follows 200 to 500 accounts, generating thousands of new posts daily. Show a personalized feed of 20 posts per screen load. The system serves 100 million daily active users.

High-Level Architecture

  User Opens App (Feed Request)
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 1: CANDIDATE SOURCING   │  (~5ms)
  │ Followed accounts + suggested │
  │ Output: ~2000 candidate posts │
  └───────────────────────────────┘
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 2: SCORING              │  (~30ms)
  │ Multi-objective deep model    │
  │ Predict engagement signals    │
  │ Output: Scored candidates     │
  └───────────────────────────────┘
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 3: POLICY & RERANKING   │  (~10ms)
  │ Content quality, diversity,   │
  │ creator fairness, ad blending │
  │ Output: Final feed (20 posts) │
  └───────────────────────────────┘

Stage 1: Candidate Sourcing

Gather candidate posts from multiple sources:

  1. In-Network: Recent posts from accounts the user follows. This is the core of the feed.
  2. Out-of-Network Suggestions: Posts from accounts the user does not follow but might enjoy, based on interest graph similarity or friend-of-friend engagement.
  3. Trending/Breaking: Globally viral content relevant to the user's interests.
  4. Reshares: Content reshared by people the user follows.

Combine and deduplicate to get roughly 2000 candidate posts.

Stage 2: Multi-Objective Scoring

A deep model predicts multiple engagement probabilities for each candidate:

Combine into a value function:

$$\text{Score} = w_1 \cdot P(\text{Like}) + w_2 \cdot P(\text{Share}) + w_3 \cdot P(\text{Long Dwell}) - w_4 \cdot P(\text{Hide})$$

The negative weight on Hide ensures that posts likely to cause dissatisfaction get demoted even if they might get stress-clicks.

Stage 3: Policy and Re-Ranking

Raw model scores are adjusted by business policies:

  1. Content Quality Signals: Demote posts flagged by a content quality classifier as low-quality, clickbait, or borderline policy violations.
  2. Diversity: Do not show 5 posts from the same creator in a row. Spread different content types (text, photos, videos) across the feed.
  3. Creator Fairness: Ensure smaller creators get minimum exposure rather than all traffic going to the top 0.1% of accounts.
  4. Ad Insertion: Place sponsored posts at positions 3, 8, and 15 (for example) with frequency caps per advertiser.
  5. Freshness Decay: Progressively discount posts that are more than 24 hours old.

Monitoring and Feedback Loops

Track online metrics after deployment:

Watch for feedback loops: if the model promotes a post early, it gets more engagement, which makes the model promote it even more. Use exploration slots (Thompson Sampling) to give new posts fair initial exposure.

Say this out loud

A social feed ranking system sources candidates from followed accounts and suggestions, scores them with a multi-objective model predicting likes, shares, dwell time, and negative signals, then applies policy re-ranking for content quality, diversity, creator fairness, and ad insertion before displaying the final feed.

Followups to expect

  1. How do you prevent misinformation from going viral? Integrate a content integrity classifier that flags posts for fact-checking. Reduce distribution of flagged content while it is under review rather than removing it immediately.
  2. How do you A/B test feed ranking changes? Split users into control and treatment groups. Measure guardrail metrics (hide rate, session time, DAU) alongside the target metric. Run the test for at least 2 weeks to capture weekly usage patterns.

Check yourself

Question 1 of 3

Why can a social feed not simply show posts in reverse chronological order?

More in ML System Design

See all →
A Framework for Any ML Design Round5 minFraming a Business Problem as ML5 minOnline vs Offline Evaluation5 min