ML System Design · Module 39 of 47 · 12 concepts · about 13 min

Design: A Personalised Social Feed

A complete design for the main feed of a social network: gathering eligible posts since the last visit, several ranking passes from cheap to expensive, predicting many kinds of interaction and combining them into one value, integrity checks, diversity and freshness, and measuring what people find meaningful rather than only what they click.

At work: Asked as 'design a news feed', 'design a home timeline' or 'rank posts for a user'. It is the canonical large-scale, multi-objective ranking problem, with unusually detailed public descriptions from the companies that run them.

Requirements

What it is

Circle, a made-up social network, ranks each user's feed. Clarify:

  • scale: 100,000,000 daily users, about 5 sessions each; each session has on the order of 1,500 eligible posts;
  • content: posts from friends, groups and followed pages: text, photos, videos, links;
  • latency: the first screen within about 300 ms; more as the user scrolls;
  • goal: people see posts that matter to them, and leave feeling the time was worthwhile; not just more scrolling;
  • constraints: integrity (misinformation, hate, spam) and user controls (unfollow, snooze, 'see less').

Why it matters

A feed is a ranking of everything a user could see, not a search over a catalogue.

  • The candidate set is defined by the user's connections, which makes retrieval simpler and ranking harder.
  • Choosing what 'good' means is the central design decision.

In the real world: Meta has publicly described ranking more than a thousand eligible posts per person per visit, for billions of people, using many models in parallel.

Proposing chronological order as the whole answer. It is a valid baseline and a user option, but at a thousand posts per session most of what matters is buried.

Framing: predict many actions, combine into value

What it is

Instead of one label, predict several, for each (user, post) pair:

  • positive: like, comment, share, click, watch time, meaningful time spent;
  • negative: hide, unfollow, report, 'see less';
  • combine into one value score: V = Σ weight × probability, with negative actions carrying negative weight;
  • surveys ('was this post worth your time?') train a model of meaningfulness, whose prediction is one more term.

Why it matters

Different actions mean different things: a comment on a close friend's post is a stronger sign of value than a like on a meme.

  • Weights let the platform say what it values, and change it without retraining.
  • Negative actions in the score stop sensational content from winning on engagement alone.

In the real world: Meta's 2021 engineering post describes exactly this: many predictions combined linearly into one value per post, with surveys used to align the weights with what people find meaningful.

Visual example

Computed

Four posts. V = 1×p(like) + 4×p(comment) + 6×p(share) − 20×p(hide). The sensational post gets many shares but loses to its hides.

Illustrative predicted probabilities and weights
postlikecommentsharehidevaluerank
Close friend's wedding photos40%12%2%0.2%0.961
Viral meme from a page25%2%6%2%0.293
Local group: road closure tomorrow8%5%4%0.3%0.462
Sensational health claim20%6%8%5%-0.084

Weighting by raw engagement volume. Shares and comments on outrage content then dominate; include negative signals and survey-based meaningfulness.

Gathering candidates

What it is

The inventory for a session:

  • posts from friends, joined groups and followed pages since the user's last visit;
  • posts ranked for an earlier session but not yet seen (they may deserve another chance);
  • older posts with new activity (a friend's post with a burst of new comments);
  • optionally recommended posts from outside the user's connections (a separate retrieval system, as in module 36).

Why it matters

Defining eligibility carefully matters as much as ranking.

  • Posts missed during a busy day should not vanish.
  • Recommended content from strangers changes the feed's nature, so its share is a product decision.

In the real world: Feed systems commonly 'fan out' new posts to followers' inboxes at write time for ordinary users and merge in posts from very popular accounts at read time.

Fetching each friend's posts one by one at request time. A user with 500 friends means 500 lookups; keep a precomputed, per-user inbox of eligible posts updated as friends post.

Ranking in passes

What it is

Score in stages, each more expensive per post (module 14):

  • pass 0: a light model picks a few hundred of the most promising posts from the inventory;
  • pass 1: the main multi-task neural network predicts every action for each remaining post, independently; most personalisation happens here;
  • pass 2: contextual re-ranking of the ordered list: diversity of authors and formats, and rules that look at the list as a whole.

Why it matters

Running the main model on 1,500 posts for every session of every user would be too slow and costly.

  • Pass 2 handles what independent scoring cannot: five videos in a row, or one friend's ten posts filling the screen.

In the real world: Meta's post names these as passes 0, 1 and 2, with a lightweight model selecting about 500 posts before the main scoring.

Visual example

Feed

Cheap filtering, rich scoring, then the list as a whole.

One feed request

  1. Inventory~1,500Posts since last visit, unseen, re-activated
  2. IntegrityRemove or demote violations
  3. Pass 0~500Light model
  4. Pass 1Multi-task network → value score
  5. Pass 2Diversity and context rules
  6. Serve and logFirst screen first

Applying diversity inside the main model. Item-level scores cannot see the rest of the list; list-level rules belong in a final pass.

Practise it: Design a Recommendation System, Design a Personalized News Feed

Features

What it is

Pass 1 features fall into groups:

  • viewer-author relationship: how often the viewer interacts with this author, messages them, views their profile; family or close-friend signals;
  • post: format, length, topic, age, early engagement (with time decay), author's typical engagement;
  • viewer: format preferences (video watcher or reader), activity level, time of day, device and connection speed;
  • embeddings of viewer, author and post content;
  • integrity scores: predicted misinformation, clickbait, low quality.

Why it matters

The relationship between viewer and author is usually the strongest signal: people care most about people they are close to.

  • Early engagement on a post must be compared fairly across post ages and audience sizes, or old and popular posts always win.

In the real world: Interaction history between viewer and author is consistently among the most important features in published descriptions of feed ranking.

Using a post's total engagement at the end of the day as a training feature. At ranking time only engagement so far is known (point-in-time, module 11).

Practise it: Design a Demand Forecasting Platform, Design a Predictive Maintenance System, Design a Real-Time Fraud Detection System, Design an ML Feature Store

The model

What it is

A multi-task neural network (module 12):

  • shared lower layers over viewer, author and post features and embeddings;
  • one head per action (like, comment, share, watch time, hide, report, survey-predicted meaningfulness);
  • calibrated probabilities per head, because they are multiplied by weights and added (module 12);
  • trained continuously on fresh interaction data.

Why it matters

Sharing layers lets rare actions (reports, shares) learn from common ones (likes, views).

  • Calibration is essential: if one head's probabilities drift upward, that action silently gains weight in every feed.

In the real world: Published feed systems describe dozens of predicted actions per post, each from a head of one large multi-task model or from separate models run in parallel.

# Pass 1: one forward pass gives every head; the value score is a weighted sum.
preds = feed_model(viewer_feats, author_feats, post_feats)    # dict of calibrated probabilities
value = sum(WEIGHTS[action] * preds[action] for action in preds)
value -= integrity_demotion(post)                              # policy, applied outside the model

Adding a new prediction head and keeping the old weights. The value scale shifts for everyone; re-tune weights by experiment after any head changes.

Integrity, controls and freshness

What it is

Beyond predicted engagement:

  • integrity: classifiers flag misinformation, hate, spam and clickbait; violating posts are removed, borderline ones demoted, regardless of engagement;
  • user controls: unfollow, snooze, 'show more' and 'show less' act directly on eligibility and weights;
  • freshness: time decay on post age, and boosts for time-sensitive content (events, breaking news from trusted sources);
  • diversity rules in pass 2.

Why it matters

Engagement models tend to reward sensational content; integrity must be enforced outside them.

  • Explicit user controls are the clearest signals the system gets, and should win over predictions.

In the real world: Feed operators publicly describe demoting borderline content and honouring snooze and 'see less' controls as rules applied on top of ranking.

Treating 'see less of this' as one more training label and nothing else. It should change the feed immediately, not only after the next retrain.

Practise it: Design an Image Search System, Design Feature Monitoring, Debug a Production ML Model, Design a Personalized News Feed

Serving

What it is

Within 300 ms for the first screen:

  • precomputed per-user inbox of candidates;
  • parallel predictors: pass 1 scoring split across machines, each scoring a slice of the candidates;
  • rank the first screen first; continue ranking in the background as the user scrolls;
  • caching of author and post features; fallback to a lighter model or recency if predictors are slow.

Why it matters

Spreading scoring across machines keeps latency flat as candidate counts vary.

  • Ranking the first screen first gets content on screen quickly.

In the real world: Meta's post describes running predictions for all candidates in parallel on many 'predictor' machines to rank a thousand-plus posts in real time.

Waiting to rank every candidate before showing anything. Users see a spinner while posts they will never scroll to are scored.

Practise it: Design Feature Monitoring, Diagnose Training-Serving Skew, Design a Model Serving Platform, Design an ML Feature Store

Evaluation

What it is

Measure value, not just activity:

  • offline: per-head AUC and calibration; NDCG of the value ranking against observed actions;
  • online: A/B tests on meaningful interactions (comments and shares between people who know each other), survey-rated worthwhile time, hides and reports, and return visits;
  • long-term holdouts for retention effects;
  • integrity metrics: prevalence of violating content seen (module 32).

Why it matters

A change that raises time spent but lowers survey satisfaction or raises reports is not a win.

  • Long-term holdouts catch changes that feel engaging now and drive people away later.

In the real world: Meta has publicly discussed shifting its feed goal towards 'meaningful social interactions' and using surveys to define what counts.

Visual example

Metrics

Activity alone is not value.

What a feed is judged on
metrictypewhy
Meaningful interactionsPrimaryComments and shares between people who know each other
Survey: worth your timePrimaryClosest measure of value
Hides, unfollows, reportsGuardrailExplicit dissatisfaction
Violating content prevalenceGuardrailIntegrity
Return visitsLong-termWhether people come back

Launching on total time spent. Outrage and endless video can raise it while people report feeling worse about the time.

Practise it: Design a Large-Scale Classification Platform, Design a Predictive Maintenance System, Design a Real-Time Anomaly Detection System, Design a Recommendation System, Diagnose Training-Serving Skew, Improve a Low-Recall Model, Design a Search Ranking System

Sources and further reading

What it is

Public work this design draws on:

  • Meta Engineering, 'How machine learning powers Facebook's News Feed ranking algorithm', 2021: inventory, passes 0 to 2, multi-task predictions combined into one value, surveys;
  • Meta AI, posts on online and offline testing of feed ranking changes;
  • Ma et al., 'Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts', KDD 2018: a common multi-task architecture;
  • Twitter's 2023 open-sourced recommendation algorithm and accompanying blog post: candidate sources, a heavy ranker and heuristics.

Why it matters

Few large systems are described in as much public detail as social feeds; using those descriptions gives your answers concrete, verifiable grounding.

In the real world: Candidates who can explain the value-score idea and why negative actions carry negative weight stand out in feed interviews.

Interview questions: the feed design

What it is

The questions interviewers ask about the feed design, from the first screening call to the senior round. Cover the answer, say yours aloud, then compare.

Why it matters

Reading an idea and explaining it are different skills.

  • Each answer below is the two or three sentences an interviewer is listening for.
  • The reasoning behind each one is in the cards above. If an answer surprises you, go back to that card.

In the real world: Feed questions are standard at social and content companies; the value-score formula and the ranking passes are the two things interviewers most want to see.

Q: What would you predict for each post?

Many actions: likes, comments, shares, watch time, and negative ones such as hides and reports, plus a survey-trained meaningfulness score, combined into a weighted value.

Q: Why rank in several passes?

A light pass cuts the inventory to a few hundred, the main multi-task model scores those, and a final pass applies list-level rules such as diversity that independent scoring cannot.

Q: What are the most important features?

The viewer's relationship with the author (interaction history, closeness), the post's format and early engagement with time decay, and the viewer's format preferences.

Q: How do you stop sensational content from winning?

Negative weights on hides and reports, survey-based meaningfulness, integrity classifiers that demote or remove content outside the model, and diversity rules.

Q: How do you serve it fast?

Precomputed per-user inboxes, parallel scoring across predictor machines, ranking the first screen first, and lighter fallbacks.

Q: How do you measure success?

Meaningful interactions and survey-rated worthwhile time in A/B tests, with hides, reports and integrity prevalence as guardrails, and long-term holdouts for retention.

Ranking by engagement alone, with no negative signals or integrity layer.

Practise it: Design a Personalized News Feed

Exercise: build a value-scored feed

What it is

A short build that uses this module's ideas. Write it yourself before looking anything up; the checks at the end tell you whether it works.

Why it matters

An idea you have only read fades in a week.

  • Building it once, even in fifty lines, is what makes it yours.
  • Interviewers can tell the difference between someone who has read about a loop and someone who has debugged one.

In the real world: Weight-sensitivity analyses like this are how feed teams explain ranking changes to policy and product leaders.

Your task. Rank posts with a multi-task model and a value score, and show how the weights change the feed.

Steps

  1. Use a public dataset with several interaction types per user and item (for example a social or news dataset with clicks, likes and shares, or simulate one).
  2. Train a multi-task model (shared layers, one head per action) or one model per action.
  3. Check calibration of each head on held-out data.
  4. Rank each user's candidates by a value score; then change the weights (for example raise the penalty on hides) and compare the top 10.
  5. Add a pass-2 rule limiting any author to two posts in the top 10 and measure the cost in value.

You are done when

  • You can show a post that moves sharply when one weight changes.
  • Each head is calibrated within a stated tolerance.
  • You can state the value given up for author diversity.

Stretch. Simulate surveys on 1% of impressions, train a meaningfulness head on them, and add it to the value score.