Loading...

A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
The signal concentrates in three places. Where you pay for the join between "who I follow" and "what they posted": at write time or at read time. What happens when a page with ten million followers posts. And what your per-user feed actually stores: whole posts or post IDs, a 50x memory difference. "Precompute the feed in Redis" is not a design until you can answer all three.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one post end to end through your diagram: Dave publishes "New job!" and it shows up when his friend Jane opens her feed. Argue the tradeoff, not "industry standard."
Read this before you go in. These are the decisions, and why they matter.
Fan-out on read (pull) stores each post once under its author and assembles Jane's feed when she asks: fetch the ~500 sources she follows, merge, sort. Writes are trivial and nothing is wasted on people who never log in. It fails on reads: 17,500 feed loads a second times 500 sources is roughly 8.75M lookups a second, far outside a 2-second budget.
Fan-out on write (push) copies the new post's ID into every follower's precomputed feed at publish time. A read becomes one cache lookup. It fails on one author: a page with 10M followers means 10M inserts for a single post, about 10 seconds even at a dedicated 1M inserts a second, against a 5-second freshness target. It also wastes work on followers who never log in.
Hybrid is the sound default. Push for ordinary users; skip fan-out for pages and public figures above a follower threshold and merge their recent posts when the reader loads the feed. Facebook caps friendships at 5,000, so friend-to-friend push is bounded; page followers are not, and those are what you pull. Tie the threshold to the freshness budget and queue lag, not to a magic number.
Equally defensible if you can say why: Facebook's real backend (Multifeed) leans toward read-time assembly, keeping every user's recent actions in memory on leaf servers and ranking at read. That works because every read is re-ranked anyway. If you argue for it, say what keeps the read fast.
Keep 500 feed items per user for 300M users. If each item is a 1 KB post, that is 500 KB a user, 150 TB, about 1,500 servers at 100 GB each. If each item is a 20-byte reference (post ID, author ID, a few flag bits), that is 10 KB a user, 3 TB, about 30 servers. Same feed, one decision apart. Store IDs, key the list by user ID, cap it (200 to 500 entries; few people scroll past ten pages), and hydrate at read time from a shared post cache where each post lives exactly once. Edits and deletes then touch one copy instead of millions.
The post request should not wait for fan-out. Persist the post, return success, and put (post_id, author) on a durable queue. Workers read the author's friend list from the social graph, filter it (muted the author, outside the post's audience, inactive for weeks), and prepend the ID to each remaining friend's feed. A durable log lets a crashed worker replay; inserting the same post ID twice must be a no-op. Put very large fan-outs in their own lane so one busy page does not delay everyone.
Jane is online when Dave posts. Holding a long poll open per user and pushing full posts is expensive at scale. Blind client polling mostly returns nothing. The pragmatic answer: send a small "new posts" signal (a WebSocket or push notification) and let the client fetch when she scrolls up or taps the banner. On mobile, where data costs money, pull-to-refresh alone is fine.
Reverse chronology is the simple default and a fair interview scope. A ranked feed changes where work happens: the precomputed list becomes a candidate source, not the answer. At read time, gather candidates (cached feed plus pulled page posts plus older posts bumped by new comments), score them on signals like likes, comments, shares, recency, media and your affinity with the author, and return the top 20. Meta runs this as a funnel: 1,000+ candidates, a light pass keeps about 500, neural predictors estimate like, comment and share probabilities, a weighted sum becomes the score, then diversity rules stop one friend filling the screen. If ranking goes down, fall back to reverse chronology rather than an error page.
Do not keep 300M feeds warm. Evict with LRU, skip inactive users at fan-out, and rebuild a feed by pull on the user's next login (slower once, fast after). Audience rules apply twice: filter recipients at fan-out, then re-check visibility, mutes and blocks at read, because relationships change after delivery. Deletes are two-stage: tombstone the post, let hydration drop it everywhere on the next read, purge IDs from feeds lazily.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
Rough numbers are fine; the method is what gets graded. The win is using them: "IDs, not posts, or the cache is 1,500 machines"; "push is fine at 520K/s but the 10M-follower page needs pull."
How the graph works: two paths share one cache. The publish path persists a post and hands its ID to fan-out workers, which read the social graph and prepend the ID into each friend's feed list in Redis. The read path pulls Jane's ID list from Redis, merges recent posts from the big pages she follows, ranks, hydrates from the post and user cache, and returns 20. Media never touches either path; it goes through a CDN.
Web Client, Mobile Client
→ Load Balancer
→ Service (Post Service; mark distributed)
→ Cassandra (posts, sharded; mark distributed)
→ Cache (post + user objects, hot tier for viral posts)
→ Kafka (fan-out topic)
→ Worker (fan-out workers; mark distributed)
↔ MySQL (social graph; TAO over MySQL at Facebook) + Cache
→ Redis (feed cache: user_id → capped list of post IDs; mark distributed)
→ Service (Notification Service) → WebSocket Server → clients ("new posts")
→ Service (Feed Service; mark distributed)
→ Redis (read Jane's ID list)
→ Cache (pull recent posts of big pages; hydrate posts and authors)
→ ML Model (ranking)
Web Client, Mobile Client → CDN → Blob Store (images, video)
Components:
(p903, dave) to the Kafka fan-out topic.p903:dave to each remaining friend's Redis feed list and trims to 500.The 10M-follower page posts: no fan-out. The post goes to Cassandra and the post cache only. Every follower's Feed Service call pulls the page's latest few posts and merges them; most readers follow only a handful of such pages, so the merge is small.
Jane was away for a month: her feed was evicted. The first read rebuilds it by pulling from her follows, stores it, and serves it. Rate-limit rebuilds so a mass cache loss does not flatten Cassandra.
Dave deletes the post: tombstone p903 in Cassandra and the cache. Hydration drops it from every feed on the next read. IDs are purged lazily or age out of the cap.
Users(user_id PK, name, profile_pic_url, created_at, last_login)
Entities(entity_id PK, type [page|group], name)
UserFollow(user_id, target_id, target_type [user|entity], created_at) MySQL, indexed both directions
Posts(post_id PK time-ordered, author_id, entity_id?, content, media_ids, audience, created_at, deleted) Cassandra
feed:{user_id} → list of post_id:author_id:flags, capped at 500 Redis list
counters:{post_id} → likes, comments, shares Redis hash
actions:{user_id}:{post_id} → liked / commented Redis or Cache
Pure read-time assembly with in-memory per-author indexes (Facebook's Multifeed) if you explain what keeps reads fast. Reverse-chronological feed if the interviewer agrees to drop ranking. Sharded MySQL instead of Cassandra for posts. SQS or RabbitMQ instead of Kafka if you address replay. Pull-to-refresh only, no WebSocket, on mobile. What matters is that you can argue the tradeoff.