Skip to content
All problems

Design a social news feed

breadth · 45 min · senior/staff

Setting

You're on the feed team at a social network where users follow other users and pages, and expect a fast, roughly-reverse-chronological (or ranked) feed of posts from everyone they follow.

The ask

Design the system that lets a user create a post and lets every follower load a personalized feed of recent posts from the people and pages they follow.

Constraints & scale

  • ~200M daily active users; average user follows ~300 accounts; a celebrity account has 50M+ followers
  • Feed load must return in < 200 ms p99 for a user opening the app cold
  • New posts should appear in followers' feeds within seconds
  • The celebrity/hot-account case (fan-out to 50M followers on every post) must not be handled the same way as a normal user's post
  • Feed ranking may consider recency, engagement, and affinity — you choose how deep to go, but the read path must stay fast either way

What a strong answer covers

Requirements → estimates (fan-out volume, storage) → API/data model → high-level diagram (fan-out-on-write vs. fan-out-on-read, and where each applies) → 1–2 deep dives → trade-offs. Likely probes: the celebrity-account hot path, feed storage/caching, and how ranking changes the architecture if you go there.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Estimates (fan-out volume, storage)
  3. API/data model
  4. High-level diagram (fan-out-on-write vs. fan-out-on-read, and where each applies)
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • The celebrity-account hot path
  • Feed storage/caching
  • How ranking changes the architecture if you go there

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Fan-out on write or on read. Precomputing each follower's feed makes reads cheap and fast and makes every post cost as many writes as the author has followers. Merging at read time makes posts cheap and reads slow and expensive. Follower count and read-to-write ratio decide it, and the problem has accounts at both extremes.
  • What the feed stores. Keeping post ids per user is small and lets edits and deletes apply once, at the cost of a hydration step on every read. Copying post content into each feed makes reads one lookup and makes deletion, edits and storage painful.
  • Ranked or chronological. A time-ordered list is a cheap append-only structure. Ranking needs features, a scoring step and often a candidate set larger than the page, which changes both storage and the latency budget. Say how much ranking you do on the read path and what you precompute.
  • Freshness against cost. Pushing every post to every active follower immediately is the most current and the most expensive. Skipping feed updates for inactive users and rebuilding on their next visit saves large amounts of work. Define "active" by something you can measure.
  • Caching the feed. A cached first page makes cold-open latency easy and goes stale or wrong when follows, blocks or deletes change. Decide what invalidates it and what staleness users will tolerate.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • One strategy for every account. Writing a post to 50 million feeds blocks queues and delays everyone else's posts, and merging 300 follows at read time for every normal user wastes the read path.
  • Duplicating full posts into each feed. Storage multiplies by follower count, and a deletion or edit has to chase every copy.
  • Ignoring unfollows, blocks and deletions. A precomputed feed will keep showing content that should be gone unless you filter at read time or clean up.
  • Forgetting the new or returning user. A user with an empty or expired precomputed feed still needs a fast, sensible first screen.
  • Hot spots in the graph store. A celebrity's follower list and their post are read by millions at once. Without caching or replication, those few keys overload a shard.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.