Facebook News Feed 00:00:01 A feed opens for just one reader Mira opens a social feed and expects a page before her train enters a tunnel. Consider one design for a Facebook-style feed. Every capacity number in the exercise is illustrative. Mira's phone requests her personal feed. Shared media can come from a CDN, while the personalized response must respect viewer-specific visibility. The feed holds compact post identifiers. Editing a post need not rewrite a large copy in every follower's list. The model scores 92 posts inside 60 ms. If not, newest first. a simple feed beats an error. 20 posts and a cursor that names the session and position 20. The cursor must preserve which ranking session the next page belongs to. Otherwise a newly published post can push a result across the page boundary while Mira scrolls. 00:00:54 Publish the post before announcing it Mira publishes her own photo. Separate the upload, the authoritative post commit and the event that lets other systems discover the new post. The app uploads straight to S3 with a signed address that lasts 15 minutes. megabytes should not pass through our services. Media belongs to the author and is ready, text length, quick safety check. Then an ID that contains the time. IDs sort by time without another index. A durable post change supplies the event used by the feed workers. In this design a change stream conveys committed publications to the queue. Only now does the worker move its position in Kafka. a crash repeats the work instead of losing it. A repeated event is normal after a worker failure. Make adding the same post to a person's feed repeat-safe before committing consumer progress. 00:01:47 A celebrity changes the economics Writing a post identifier into a few hundred followers' inboxes buys a cheap future read. A celebrity with millions of followers changes the cost and the time until everyone sees it. The event holds the post ID, author and time. 430 small inserts. Reading is now one lookup. Each feed server adds the ID to the star's short list in its own memory. All big accounts together are 2 GB. It adds recent posts of the big accounts this reader follows. A set removes IDs that came both ways. Choose the fan-out boundary from active readers, publication rate and freshness needs. A hybrid reader merges prebuilt candidates with recent posts from unusually expensive accounts. 00:02:33 Spend the ranking budget in passes A two-hundred-millisecond page budget leaves only a portion for scoring. The ranking service should never spend that portion on a post Mira is already forbidden to see. The page must be ready in 200 ms, of which ranking may use 60. Headers show 8 posts the viewer may not see. They go before any score. It predicts the chance of a like, comment, share and hide. The first 20 are hydrated. The rest wait in the session. Enforce current visibility again on sensitive reads. When the ranker misses its deadline, a bounded fallback can still return eligible posts. 00:03:11 Repair a cold feed without a stampede A reader who has been away for a month can have an empty materialized feed even while hundreds of followed authors have durable posts. Rebuilding that list at every request would magnify the cost. The owner was away for a month, so the feed expired. It shows popular posts for the region. something now beats everything later. Recent posts of 500 followed accounts are read from the author table. One read instead of 500. The durable post store owns the content. A feed is a reconstructed, ranked view whose staleness and failure behavior have to be designed as deliberately as its happy path.