Skip to content
Commitwise
Menu

Design a news feed: how do posts get into followers' feeds?

System designSenior

In shortA hybrid of fan-out on write and fan-out on read: for most users, new posts are pushed into followers' precomputed feed caches; for accounts with huge follower counts, posts are pulled and merged at read time. Feeds store post ids, ranking happens at read time, and pagination uses cursors.

Model answer

Fan-out on write (push): when a user posts, a worker appends the post id to each follower’s feed list (Redis sorted sets or a wide-column table, trimmed to the latest few hundred). Reads are fast: fetch ids, hydrate. Writes cost one insert per follower, asynchronous through a queue.

Fan-out on read (pull): at read time, fetch recent posts from everyone the user follows and merge them. Writes are cheap; reads are expensive for users who follow many accounts.

Hybrid: push for normal accounts; for accounts above a follower threshold (celebrities), skip fan-out and merge their recent posts at read time. Inactive users can be skipped during fan-out and rebuilt on their next visit.

Read path: get candidate ids from the feed cache plus pulled celebrity posts → hydrate (batch-fetch posts, authors, counts from caches) → rank (recency plus engagement signals, possibly an ML ranking service) → return a page with an opaque cursor. Filtering (blocked users, deleted posts) happens at hydration.

Storage: posts in a sharded store keyed by post id; social graph in a store optimized for follower lists; media on a CDN.

Mobile: cursor-based pagination, prefetching the next page, caching the first page for instant start, showing “new posts” banners instead of shifting content under the user’s finger.

What they're looking for

Fan-out on write vs read with the celebrity problem, feed storage (lists of ids in Redis or a wide-column store), hydration, ranking, cursor pagination, caching, and mobile considerations.

Common mistakes

  • Pure fan-out on write, which explodes for accounts with millions of followers.
  • Offset pagination for a feed that changes constantly.
  • Storing full post content in every follower's feed.

More system design questions

Esc

Type to search the whole site.