AlgoViz

Design a news feed like Facebook's

hard 50 min

Show each person the best recent posts from everyone they follow, in a fifth of a second.

Agree on the scope

Ask what changes the design, then commit to a short list.

Clarifying requirements

  1. Interviewer

    Let's design Facebook's news feed. What would you ask?

  2. You

    Scale first, then features, then limits:

    • How many daily users? I will assume 2 billion.
    • How many friends and follows on average? I will assume 500 in all.
    • How often do people open the feed? I will assume 10 requests a day, of which 3 start a visit and 7 ask for more.
    • How many post? I will assume 20% of users, one post each a day.
    • Is the order by time, or ranked?
    • Text, photos, video? Who may see a post?
    • Must new posts appear without a refresh?
  3. Interviewer

    Those are fine. Ranked, with photos and video, audience settings, and live hints. Some accounts have 100 million followers. How does that affect you?

  4. You

    It decides the design. A normal post is 500 small writes. That account's post is 100 million for one click of a button, and everyone else's posts wait behind it. So I expect two paths: push for normal accounts and pull for big ones.

  5. Interviewer

    Which quality targets would you set?

  6. You

    In order: availability, then latency, then freshness.

    • First page in 200 ms at p99, measured at our servers.
    • 99.99% available, about 53 minutes a year. Never an empty feed.
    • A normal post reaches friends' feeds in 5 seconds; a hint to open apps within 10.
    • Your own post is visible to you at once.
    • An unfriend, block or deletion applies to the next feed request.
    • Posts are durable before we say "posted". Ready feeds may be lost and rebuilt.

In scope

  • Personal feed, ranked, endless scrolling
  • Create, edit and delete posts with text, photos, video, links, places
  • Audience: public, friends, custom list, only me
  • Like, comment, share and reaction counts
  • Hints that new posts exist
  • Reach and reaction numbers for authors

Out of scope for now

  • Ads and billing
  • Messaging
  • Training the ranking model
  • Full search
  • Live video

Quality targets

QualityTargetWhy
Latencyfirst page under 200 ms p99It is the first screen of the product
Availability99.99%, with degraded modesA simple feed beats an error page
Freshness5 s for normal posts, 10 s for hintsSeconds are fine; minutes feel broken
Consistencyeventual for feeds and counts, your own posts at onceNobody can compare two people's feeds
Privacycorrect on the next requestA wrong audience is a real harm
Durabilityno lost postsFeeds can be rebuilt; posts cannot
Spikes3x peak daily, 10x events with degraded modesElections, finals, outages elsewhere

Each answer changes the design

You askIf the answer isThen
Ranked or newest first?Newest firstNo ranking service, and the cursor is simply a post ID
Is there a follower limit?Yes, 5,000Push for everyone; no big account path
How many users?100,000One database and a good query; stop at version 1
Must hints be instant?Within 100 msOpen connections for all, no batching, far more servers
Can posts be edited?YesFeeds must hold IDs, not copies
Are reads mostly by a few active users?YesPush only to warm feeds, rebuild the rest