Design a News Feed and Timeline

A feed combines content creation, relationship data, ranking, and low-latency reads. In a fan-out-on-write design, a new post is written into followers' feed timelines. Reads become fast, but a celebrity with millions of followers can create a huge write burst.

In fan-out-on-read, the service gathers posts from followed accounts at request time. Writes are cheaper, but reads can require many merges and may be slow for users following many accounts. Hybrid approaches precompute ordinary users' feeds while fetching very high-fan-out accounts at read time.

Store post metadata separately from media blobs, cache hot timelines carefully, and make ranking a distinct stage. Define pagination with stable cursors and consider deleted posts, blocked users, privacy changes, and eventual consistency. Feed correctness includes authorization and visibility, not just speed.

Key Takeaways
  • Fan-out-on-write optimizes reads but can amplify writes.
  • Fan-out-on-read moves work to the read path.
  • Hybrid designs address skew; visibility rules must remain correct.