MongoDB
Designing Twitter/X at Scale
A comprehensive system design walkthrough for building a Twitter-like platform — tweets, timelines, trending topics, and search.
S
srikanthtelkalapally888@gmail.com
Designing Twitter/X at Scale
Twitter serves 500M daily users posting 500M tweets per day.
Core Features
- Post tweets (280 chars, media)
- Follow/Unfollow users
- Home timeline
- Trending topics
- Search
Data Estimations
Tweets/day: 500M
Read:Write ratio = 100:1
Peak reads: ~600K/sec
Storage: ~500GB/day (text only)
Tweet Storage
- Tweets: MySQL (strong consistency for writes)
- Media: S3 + CDN
- Timeline Cache: Redis sorted sets
Timeline Architecture
Hybrid fan-out:
- Regular users: Precomputed feed pushed to Redis
- Celebrities (>5K followers): Lazy fan-out at read time
Timeline = Precomputed_feed + Celebrity_tweets (merged at read)
Trending Topics
- Count hashtag frequency in 1-hour sliding windows
- Use Apache Flink for real-time stream processing
- Store top-50 trending in Redis
- Personalize by location
Search
- Elasticsearch indexes all tweets
- Inverted index on words
- Near real-time indexing via Kafka connector
Media Upload
Client → Upload Service → S3
↓
CDN Distribution
Conclusion
Twitter's architecture is a masterclass in read optimization — hybrid fan-out, Redis timelines, and Elasticsearch power the platform at scale.