Design the home feed for a social network. Users follow other users and see their recent posts, newest or highest-ranked first. Some accounts have millions of followers.
Functional requirements
Publish a post
Fetch a paginated home feed
Follow and unfollow users
Non-functional requirements
Feed loads in under 300 ms at p99
New posts appear in followers' feeds within 10 seconds
Celebrity posts must not overload the system
Constraints and scale
300 million daily active users
Average user follows 200 accounts
Top accounts have 50 million followers
You will practise
Choose between fan-out on write and fan-out on read
Handle hot keys
Cache precomputed feeds
Show 2 hints
Fan-out on write is cheap for small accounts and expensive for celebrities
Feeds are read far more often than posts are written