Design an Instagram-like Feed System
OpenAISoftware Engineer · Technical ScreenLast updated
This question assesses the ability to architect a high-scale feed system by balancing pre-computation (push model) versus on-demand computation (pull model) to minimize latency for social media users.
Problem Statement
Design an Instagram-like news feed system. Users follow other users, and when they open the application, they see a ranked list of posts from the people they follow.
Functional Requirements
- Users can post content (images/text).
- Users can follow other users.
- Users can view their personalized feed.
Non-Functional Requirements
- High read availability: Feed viewing is the most frequent operation.
- Low latency: The feed must load in under 200ms.
- Scalability: The system must support millions of daily active users and handle "celebrity" users with millions of followers.
Expectations
Provide a high-level design that addresses:
- Data model: How to store users, follows, and posts.
- Feed Generation: How to construct the feed (Push vs. Pull approach).
- Scalability: How to handle the "celebrity" problem (e.g., an account with 10M+ followers).
- Storage: The trade-offs between SQL and NoSQL databases for this use case.
Example Flow
- User A follows User B.
- User B posts an image.
- User A logs in and fetches their feed. The system must retrieve the most recent posts from all followed accounts, ranked by time and relevance.
Hints
Hint 1
Consider the trade-offs between a 'pull' model (fetching feeds at read-time) versus a 'push' model (pre-computing feeds into a cache upon posting).
Hint 2
How does the performance of a push model degrade when a user with millions of followers posts a new update?
Hint 3
Think about how caching strategies (like Redis) can alleviate the load on your primary persistent storage.
Follow-up questions
- How would you modify your design to support a ranking algorithm that displays posts based on user engagement rather than simple reverse-chronological order?
- If we implement a 'push' model, how would you handle the 'celebrity' problem to avoid excessive fan-out writes?
- How would you ensure feed consistency if a user deletes a post shortly after publishing it?
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.