Design a news feed like Instagram or Facebook

A feed shows posts from people you follow, fast. The key choice is when to build each user's feed: at write time or at read time.

A stream of posts reaching many followers

Goal: each user sees a feed of recent posts from the accounts they follow, loading in well under a second.

Requirements

  • Publish a post. See a feed of followed accounts' posts, newest or ranked first.
  • Feed loads fast, with pagination.
  • Users follow thousands of accounts, and some accounts have millions of followers.

The core problem

When user A posts, it must appear in every follower's feed. When B opens the app, we must produce B's feed quickly. There are two ways.

Fan-out on read (pull)

When B opens the feed, fetch the latest posts of everyone B follows, merge and sort.

  • Simple writes, no storage duplication.
  • Slow reads: B may follow 1,000 accounts, so 1,000 lookups per request.

Fan-out on write (push)

When A posts, push the post ID into each follower's precomputed feed (a list in Redis or a database).

  • Very fast reads: just read your own list.
  • Expensive writes: a celebrity with 10 million followers means 10 million inserts per post.
  • Wasted work for inactive followers.

The usual answer: hybrid

  • For normal accounts, push to followers' feeds.
  • For celebrities (above a follower threshold), don't push. At read time, merge the precomputed feed with a quick pull of the celebrity posts.
  • Skip precomputing for inactive users.

Data model

  • posts(post_id, author_id, content, media_url, created_at)
  • follows(follower_id, followee_id)
  • feed(user_id) -> list of post_id, kept to the latest few hundred entries in Redis.

Feed stores IDs only. A separate step loads post details, author info and counts, ideally from a cache.

Reading and pagination

Use cursor-based pagination (by post ID or time), not page numbers, so new posts don't shift the pages.

Ranking

Pure time order is simplest. Ranked feeds score posts with signals like recency, relationship strength and engagement, usually in a separate ranking service on a short candidate list.

Media

Images and video live in object storage behind a CDN. The feed carries URLs only.

Takeaway: use a hybrid fan-out, store IDs in per-user lists, hydrate from caches, paginate with cursors, and keep media on a CDN.


System Design series, Part 3 (case studies): 4 of 16. Previous: Design a chat app like WhatsApp.

Keep reading

Also on Newssite