How would you design a Twitter/social media feed?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

Designing a news feed is one of the most common system design questions. Core challenge: when user A opens their feed, show recent posts from people A follows, ranked by recency (or algorithm). Two approaches: Push (Fan-out on write): when user X posts, immediately push the post to all X's followers' feed caches. Feed reads are fast (just read from the user's pre-computed feed). Cons: celebrities with millions of followers write to millions of caches — too slow for hot users. Pull (Fan-out on read): when user A views their feed, query the latest posts from all A's followees, merge and rank in real-time. Simple writes. Cons: reads are slow (query N followees' posts, sort, deduplicate). Bad for users following thousands of people. Hybrid approach (Twitter/Facebook approach): push for regular users (up to 10K followers); pull for celebrities (defined threshold). Regular users get fast reads via pre-computed feed; celebrity posts are pulled and merged on read. Data model: users table, follows table (follower_id, followee_id), tweets table (tweet_id [Snowflake ID], user_id, content, created_at), feed_cache (user_id → sorted list of tweet_ids, stored in Redis sorted set with score = timestamp). Timeline storage: Redis sorted sets — ZADD timeline:{user_id} {timestamp} {tweet_id}; ZREVRANGE to fetch. Evict old entries (keep last 800 tweets per user). Media: images/videos in S3, served via CDN. Scale: read heavy (100:1 read:write), cache aggressively.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last System Design project, I used this when...' immediately makes your answer more credible and memorable.