Design a news feed (like the Twitter/X home timeline).
Answer
- Posting: store the post; publish an event.
- Fan-out on write (push): add the post ID to each follower's cached timeline (Redis lists). Fast reads, expensive for celebrities with millions of followers.
- Fan-out on read (pull): merge followed users' recent posts when the timeline is opened. Cheap writes, slower reads.
- Hybrid: push for normal users, pull for celebrities at read time.
- Timelines store IDs; load post and user details from caches.
- Ranking service, cursor pagination, media via CDN, counters updated asynchronously.
Practice this question in Repaso