Answer
Requirements: users publish posts and see a feed of recent posts from the people they follow, loaded quickly and possibly ranked. Reads vastly outnumber writes.
- Components: a post service and store, a social graph service for follow relationships, a fan-out service, a feed cache holding a list of post IDs per user (for example, Redis lists), and a feed service that hydrates IDs into full posts.
- Fan-out on write (push): when a user posts, insert the post ID into every follower's cached feed; reads are fast, but writes are expensive for accounts with millions of followers.
- Fan-out on read (pull): assemble the feed at read time from followed users' posts; writes are cheap, reads are slow.
- Trade-off: most designs use a hybrid, pushing posts from ordinary users and pulling celebrities' posts at read time, then merging the two.
More in Social Platforms
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Design a photo-sharing service like Instagram | Concept | Medium | Read the answer to Design a photo-sharing service like Instagram | |||
| 2 | Design a typeahead (search autocomplete) system | Concept | Medium | Read the answer to Design a typeahead (search autocomplete) system | |||
| 3 | Design a news feed system | Concept | Hard | Read the answer to Design a news feed system | |||
| 4 | Design a chat application like WhatsApp | Concept | Hard | Read the answer to Design a chat application like WhatsApp |