Facebook News Feed

Ranked social feed

Design a ranked feed of posts from friends, groups and pages, where every post has its own audience, the feed is assembled when it is read, and machine-learned models choose the order.

Overview

A news feed shows each person recent posts from their friends, the groups they joined and the pages they follow, ordered so the most valuable ones come first. It looks like the Twitter timeline problem, and the Twitter / X topic covers the parts they share: fan-out on write versus read, the celebrity problem, and time-ordered IDs. This topic is about what makes a Facebook-style feed different.

Three things change the design.

  • Friendship is mutual and posts have audiences. A post can be public, for friends, or for a custom list. The same post is visible to one viewer and invisible to the next, and a block or an unfriend must take effect at once.
  • The feed is ranked, not chronological. Meta describes scoring more than a thousand candidate posts per person per day with neural networks, combining predicted actions into one value per post.
  • Meta built it by assembling feeds at read time. Its Multifeed system looks up a person's friends, finds their recent actions in an in-memory index, and ranks them on each request, rather than copying posts into per-user feed lists.

Questions to ask first

  • How many users and feed loads? — 1 billion daily users, about 10 feed loads each a day
  • Who can see a post? — Public, friends, or a custom list; blocks always win
  • Chronological or ranked? — Ranked by predicted value; a chronological view is a variant
  • How fresh? — A friend's post appears on the next feed load, within seconds
  • How many friends? — A few hundred on average, capped at a few thousand
  • Which content? — Posts from friends, groups and pages; no ads here

What you will be able to do

  • Explain why a feed with per-post audiences is usually assembled at read time, and what that costs.
  • Describe the aggregator and leaf design, and a graph store built on objects and associations.
  • Enforce privacy, blocks and deletes on every read without touching millions of cached lists.
  • Walk through multi-pass ranking: inventory, a cheap first pass, the main scoring pass, and context rules.
  • Page through a ranked feed consistently and show new posts without reshuffling it.

Key concepts

  • Mutual friendship graph
  • Per-post audience
  • Read-time aggregation
  • Aggregator and leaf
  • TAO objects and associations
  • Candidate inventory
  • Multi-pass ranking
  • Weighted prediction score
  • Ranked-session cursor

Functional requirements

  • Create a post with an audience: public, friends, or a custom list
  • Open a ranked home feed of friends', groups' and pages' posts, and page through it
  • Like and comment; these feed back into ranking
  • Never show a post to someone outside its audience, or from or to a blocked user
  • Show that new posts are available without reordering what is on screen

Non-functional requirements

  • First feed page in under 500 ms at p99 (a target we chose), ranking included
  • Privacy is never eventually consistent: a block or audience change applies to the next read
  • Posts and interactions are durable once acknowledged
  • The feed degrades (fewer candidates, simpler ranking) rather than failing

Interview questions

  • Fan-out on write or on read for this feed? Why?
  • How does read-time assembly stay fast?
  • How do you store the social graph?
  • How do you guarantee that private posts never leak?
  • Walk me through how the feed is ranked.
  • How do you paginate a ranked feed?
  • What happens when part of the system is slow?
  • How does this differ from designing the Twitter timeline?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio