Every tweet gets a time-sortable ID and is stored once, then a fan-out service copies its ID into each follower's cached home timeline so reading a timeline is a single lookup. Accounts with huge followings are handled the other way round: their tweets are merged in when a follower reads. A stream processor counts hashtags to surface trends.
Functional requirements
- Post short tweets with optional images, replies and retweets
- Follow and unfollow users
- Home timeline of tweets from people you follow, newest (or most relevant) first
- User timeline showing one person's tweets
- Like and retweet; search tweets and hashtags; see trending topics
Non-functional requirements
- Extremely read-heavy: timeline reads outnumber tweets by ~10×
- Home timeline loads in a few hundred milliseconds
- A new tweet should reach followers within seconds (eventual consistency is fine)
- Highly available; tweets are never lost once acknowledged
Extensions
- Ranked ('For you') timelines scored by an ML model instead of pure recency.
- Notifications for mentions, likes and new followers.
- Direct messages over persistent connections.
- Spam and abuse detection on the event stream.