Design a News Feed (aka Twitter) π±
A news feed is a constantly updating list of posts and updates from people you follow. It is the core feature of platforms like Twitter, Instagram, and Facebook.
This content is adapted from Mastering System Design from Basics to Cracking Interviews (Udemy). It has been curated and organized for educational purposes on this portfolio. No copyright infringement is intended.
π Introduction
Designing a news feed at scale involves handling massive "Fan-out" (distributing one post to millions of followers) while maintaining sub-second latency for feed loads.
Core Functional Requirements
- Post Updates: Users can post short text updates and media.
- Follow/Unfollow: Users can follow others to see their updates.
- View Timeline: A feed of posts from all followed accounts, sorted by time or relevance.
- Engagements: Support for likes, replies, and retweets.
Non-Functional Requirements
- Low Latency: Feeds must load instantly (< 200ms).
- High Availability: System must remain accessible even during viral events.
- Scalability: Support hundreds of millions of daily active users (DAU).
- Data Consistency: Posts should not be missing or duplicated in the feed.
π Scale Estimation
To design for the right scale, we assume Twitter-like volume:
- DAU: 200 Million
- Tweets/day: ~1 Billion
- Feed Requests/day: ~2 Billion (Users check 10 times a day)
- Media Storage: ~300M uploads/day requiring ~100-500TB of storage.
- Read/Write Ratio: Extremely read-heavy (~80% reads).
π High-Level Architecture
The system is split into two primary flows: Write Path (posting a tweet) and Read Path (loading the timeline).
π Timeline Generation Strategy
The biggest challenge is Fan-out: how do we show one tweet to millions of followers?
Fan-out on Write (Push Model)
- Mechanism: When Bob tweets, the system pushes the tweet ID directly into the pre-computed timeline caches of all his followers.
- Pros: O(1) read latency. Loading the feed is just a simple cache fetch.
- Cons: Write Storms. If a celebrity with 10M followers tweets, the system must perform 10M writes instantly.
ποΈ The Final Design

π οΈ Bottlenecks & Challenges
- Hotspotting: Celebrities with 100M+ followers cause significant traffic spikes. Sharding by
user_idand using the Hybrid Fan-out model mitigates this. - Media Delivery: Timeline content is heavy. Using a Global CDN is essential to ensure images and videos load seamlessly across the world.
- Write Amplification: A single tweet results in many operations (DB write, Media link, Fan-out, Notifications). Decoupling these via Asynchronous Queues (Kafka) ensures the "Tweet Button" is always responsive.
π‘ Top Interview Questions
Q: Why use Cassandra for tweets? Cassandra is optimized for high-volume writes and is highly scalable geographically. It handles a massive number of small rows (tweets) efficiently.
Q: How do you handle pagination? Use Cursor-based pagination (using the tweet ID or timestamp) instead of Offset-based. Offsets become increasingly slow as you scroll deeper into the feed.