News feed
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Design a news feed: the 60-second story

    Design a news feed

    Open the app, and 20 posts appear, picked from a thousand.

    Every post must reach hundreds of readers, or a hundred million. And the list keeps changing under your thumb.

    200×

    feed writes for every post you push

    Assume about 300 followers, two-thirds active this week. A billion posts a day becomes 2.3 million list inserts a second, 7 million at peak.

    Who pays: writer or reader?

    Bad: Pull on every open

    300 followee lookups per page, 138M a second at peak.

    Good: Push IDs to live lists

    ≈ 200 inserts per post. A feed open is one memory read.

    Push or pull? It depends on the pair.

    Push when the reader looks often compared with how often the author posts. Deciding pair by pair minimises the total cost.

    A film star posts to 100M followers. Pushing it eats 43 seconds of the whole fan-out fleet.

    The trick

    Don’t push. Hot accounts write to one cached outbox; readers pull about ten and merge.

    1,000 candidates, 20 slots, about 180 ms

    Cheap passes protect the expensive one. Filters, a light model keeps 500, a heavy model scores them, then diversity rules fill the page.

    Three friends post while you scroll. Page 2 repeats.

    Offsets shift under new posts. Instead, rank once per session, store the 500 IDs as a snapshot, and page with a cursor into it.

    Deletes and privacy: filter, don’t retract

    1. Feeds hold IDs, never copies of posts
    2. Check the live post at every hydration
    3. Hydrate 24 to show 20
    4. Retract only reader-side changes, like unfollows

    Remember

    Push IDs to active readers, pull from hot authors. Rank once per session, page a snapshot, and check privacy on the live post.