Lesson 6 of 15
37. Design a News Feed

37.5 What does the whole system look like?

3 min read+10 XP

Step 4: High-level design (10 minutes)

posting writes to the posts store and publishes an event; fan-out workers push IDs into followers' feed caches, skipping celebrities and inactive users; the feed service reads the cache, pulls celebrity posts, ranks and hydrates.

Figure: the final design. Feeds hold IDs; the ranker merges, scores and fills in the details at read time.

Posting, step by step:

  1. The author posts; the post service saves it in the posts store and publishes post_created (via an outbox, Chapter 23).
  2. Fan-out workers read the event. If the author is a celebrity, they do nothing more. Otherwise, they read the author's followers from the follow graph, skip those inactive for 30 days, and prepend the post ID to each follower's feed cache (trimming to 800).

Reading, step by step:

  1. The reader opens the app; the feed service reads their cached list of post IDs.
  2. It pulls recent posts from the few celebrities they follow.
  3. The ranker scores the merged candidates (37.8), applies rules, and takes the top 20.
  4. It hydrates them: post bodies, author names and like counts from caches.
  5. It stores the ranked order as a session snapshot and returns the first page with a cursor (37.9).

Inactive users who come back have no cached feed: build it on read (pull from everyone they follow), then cache it.

Interviewer pushback:

  • "A follower is added after a post was fanned out." → New follows backfill: copy the followee's recent posts into the follower's feed when they follow.
  • "The feed cache loses a shard." → Rebuild affected feeds on read from the follow graph and posts store, the same path as returning inactive users.

Memory code: "Push IDs to most, pull from the giants, rank at the door."


Offer: "The interesting parts are fan-out, the celebrity problem, ranking, and pagination. Which would you like?"