News Feed Interview Questions
How would you design a news feed (Twitter/Facebook style)? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
How would you design a news feed (Twitter/Facebook style)?
The hard part is fan-out. Fan-out on write: when I post, I push the post id into every follower's feed cache. Reads are fast, but a celebrity with 50 million followers will kill the write path. Fan-out on read: at read time I pull recent posts from people I follow. Better for huge followings, slower reads. The hybrid I would propose: fan-out on write for normal users, fan-out on read for celebrities. Feed cache stores post ids, not full posts. Ranking can be recency first, then an async ML ranker. I paginate with cursors, not SQL OFFSET. Likes and view counts should not live on the same hot row as the post body.
Fan-out on write versus fan-out on read for a Twitter-style feed?
Fan-out on write: when I post, I push the post id into each follower's timeline cache. Reads are fast. It hurts celebrities with millions of followers. Fan-out on read: I pull recent posts from people I follow at read time. Writes are cheap, reads are heavier. Hybrids push to active users and pull for the rest. I would pick hybrid for a Twitter clone. I would not only draw a queue and stop.
How do you rank a feed — chronological or relevant?
I would start chronological because it is explainable and debuggable. Then I add a ranker: recency, affinity, and predicted click, computed offline and applied at read. I would keep a kill switch back to chronological. I would not claim I will train a huge model in the interview. I would say I need metrics — dwell time, hides, reports — and that ranking without safety will amplify junk.
How do you handle a celebrity posting to 50 million followers?
I would not write 50 million timeline entries inline with the post API. I would enqueue fan-out, shard workers by follower id, and for inactive users skip write and let them pull. The celebrity's post is stored once. I would cache the post body heavily. I would rate-limit notifications. This is why hybrid fan-out exists. I mention backpressure so the post API stays fast.
Where do likes and comments live relative to the feed?
The feed stores post ids, not full comment threads. Counts can be cached and updated async. Opening a post loads comments from a separate service, paginated. I would not embed all comments in every follower's timeline copy. Likes are a counter plus a user-like relation for 'have I liked this'. Eventual consistency on counts is usually fine. Exact counts on a viral post are expensive and I would say so.
Practice with AI mock interviews
Run System Design mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required