Codacoda
Back to Academy

system design

News Feed

Design a social media news feed system that aggregates and ranks posts from followed users. The two main approaches are fan-out on write (push model), where a new post is immediately written to all followers' feeds, and fan-out on read (pull model), where the feed is assembled at read time by querying all followed users' posts. Key trade-offs include write amplification versus read latency, storage cost of pre-computed feeds versus CPU cost of on-the-fly assembly, and handling celebrity users with millions of followers. A ranking layer scores posts by recency, engagement, and relevance to personalize the feed.

Use Cases

  • Social media platforms like Twitter/X and Instagram
  • Content aggregation services like Reddit or Hacker News
  • Activity feeds in collaboration tools showing team updates
  • E-commerce product recommendation feeds

Visualization

OVERVIEWClientMobile / WebAPI ServerFeed ServiceFan-out ServiceAsync WorkerPush to cachesPost DBPostgreSQLPosts tableFeed CacheRedisuser -> post IDsUser GraphGraph DBFollowers
Speed:1x
News Feed: users create posts that appear in followers' feeds. Fan-out on write pre-computes feeds. Key: Post DB, Fan-out Service, Feed Cache, User Graph.Step 1 / 7

Implementation

Output

Click "Run Code" to see output...