Skip to content
Design Questions
- A user can publish a post and see friends’ posts on the news feed page
- Feeds are sorted by reverse chronological order
- Feeds can contain images, videos
- Traffic volume, e.g. 10 million DAU
CUJ: News Feed Publishing
- Micro service design. The system contains following components: API servers, Post service, Fanout service, Notification service.
- API servers: API servers: serve news feed publishing requests and send out sub requests to post service, fanout service and notification service.
- Post service: write the post to Post Cache and Post DB
- Notification service: inform friends that new post is available
- Fanout service: Two types of fanout model
- Fanout on write (push model): when a post is published, pre-calculate the news feed for friends and deliver to their new feed cache.
- Pros: news feed retrieval is fast, news feed can be pushed to friends immediately
- Cons: Hotkey problem for users who have lots of friends. For inactive friends, pre-computing new feeds is a waste.
- Fanout on read (pull model): news feed is generated during the read time.
- Pros: No hotkey issue for users who have lots of friends. For inactive users, we generate news feeds in a lazy way to save resources.
- Cons: Fetching news feeds could be slow
- Hybrid approach
- Avoid fan-out for celebrities (users who have lots of friends)
- Fetch friends IDs
- Filter out inactive users, muted users etc.
- Insert the current post to each friend’s News Feed Cache
CUJ: News Feed Retrieval
- Fetch all friends IDs
- Get latest post for celebrity friends from Post DB
- Get latest post for non-celebrity friends from News Feed Cache
- Return the final news feed
Cache architecture
- Cache is extremely important for a news feed system. All following components utilize cache to speed up read operations.
- New feed cache, Content cache, Social Graph cache (follower, following), Action cache (liked, replied, others), Counters cache (like counter, reply counter, other counter)