Design a Scalable News Feed
AmazonSoftware Engineer · Technical ScreenLast updated
This problem evaluates your ability to design a feed generation architecture, specifically comparing push vs. pull models for users with varying follower counts.
System Design: Scalable News Feed
Design a backend service that generates a personalized 'Home Feed' for a social media application. Users can create posts, follow other users, and view a feed consisting of the latest posts from those they follow.
Requirements
Functional Requirements:
- Users can post content (text/images).
- Users can follow/unfollow other users.
- Users can view their feed, which displays posts from followed users in reverse chronological order.
Non-Functional Requirements:
- High availability and low latency for feed retrieval.
- The system must support at least 100 million daily active users.
- Feed updates should appear within a few seconds of a post being published.
Scope
Your response should cover:
- High-level architecture and API design.
- Data schema for users, follows, and posts.
- The mechanism for feed generation (Push vs. Pull strategy).
- Handling of 'Celebrity' accounts (users with millions of followers) to prevent system bottlenecks.
- Caching strategy to optimize read performance.
Hints
Hint 1
Consider the trade-offs between 'Fan-out on write' (push) and 'Fan-out on load' (pull) strategies based on a user's follower count.
Hint 2
Think about how to prevent a celebrity account's post from triggering millions of simultaneous database writes when they publish a new update.
Hint 3
Decide whether to store the feed in a relational database or a NoSQL key-value store, and why one might be better for high-read throughput.
Follow-up questions
- How would you modify the system to support a 'ranked' feed based on engagement rather than strictly reverse-chronological order?
- If a user deletes a post, how do you ensure it is removed from all feeds in a distributed system?
- How would you handle the storage and delivery of media content associated with posts to minimize latency?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.