Lesson 29 / 32
Design a News Feed
Fan-out strategies for showing followed content, ranked, fast.
Requirements
Users follow others and post updates; opening the app shows a ranked feed of recent posts from people you follow. Assume most users follow hundreds, some celebrities have tens of millions of followers.
Push (fan-out on write)
When a user posts, immediately write that post into every follower's precomputed feed (a list in Redis). Reading the feed is then one fast lookup. Great for typical users — terrible for a celebrity with 50M followers (one post = 50M writes).
Hybrid: push for most, pull for celebrities
Like a newspaper delivering to most houses (push) but leaving today's front page at newsstands for a few very popular columnists (pull) — most systems push to normal followers' precomputed feeds and, at read time, merge in a live pull of any celebrity accounts the user follows.
Ranking is a separate concern
Fan-out solves delivery; a separate ranking service (recency, engagement prediction) reorders the candidate posts at read time. Keep the storage/delivery pipeline dumb and fast, and ranking pluggable.