CodingNodes Space play · ←→ step · R restart

The problem

A news feed is a read-heavy product that is secretly defined by its writes. When a user posts, the question is not 'store the post' — it is 'how many other feeds does this post have to appear in, and when do they get it'. That fan-out question is the whole design: answer it at write time and reads are a trivial fetch, answer it at read time and every open is an expensive join.

We will pin down the numbers, then walk the write path that builds each follower's inbox ahead of time, the read path that simply fetches it, pagination with a cursor that never skips a post, the media pipeline that turns an upload into a CDN URL, and the ranking pass that orders what is already there. By the end, a post has traveled from one user's screen to a million followers' feeds, and we know exactly when each piece of that journey happened.

Requirements

Functional — what it must do

  • Post: a user creates a post — text, optionally with media — and it becomes visible to the feeds of the users they chose to share it with.
  • Read: a user opens their feed and sees the posts from people and pages they follow, in the order the system decided, with pagination for more.
  • Media: a post can carry images or video; the raw upload is processed into viewable sizes and served from a CDN, not the origin.

Non-functional — how well it must do it

  • Opening a feed is a fetch, not a computation: the common read answers in low single-digit milliseconds from a pre-built inbox.
  • A post to a user with many followers must not block the poster's response; fan-out is asynchronous and survives a follower count in the millions.
  • Pagination must be stable: scrolling down never duplicates or skips a post, even while new posts land at the top.

Scale — how much it must take

  • On the order of a hundred million daily active users, a few million posts per hour, and a small number of mega-followers with millions of followers each.

Assumptions — the numbers this design is sized for

A rate limit means nothing without a scale. These are the figures every later part relies on: how much traffic arrives, how much work the limiter has to do per second, and how much latency and memory it may spend doing it.

DAU
~100M
The number of people whose feeds must exist. Most are readers, not posters.
Posts
~3M / hour
The write rate the fan-out path must absorb. Lower than the read rate by a wide margin.
Read/write
~100 : 1
Feeds are opened far more often than posts are made. That ratio is why reads must be the cheap path.
Avg followers
a few hundred
Most posts fan out to a few hundred inboxes. A handful of mega-followers fan out to millions.
Mega-fan-out
up to ~2M
The outlier a naive write-ahead cannot survive. Handled by a different strategy, not a bigger database.
Feed read
< 10 ms p99
Opening a feed must feel instant. It is a fetch of a pre-built inbox, not a join.
Page size
20 posts
Each feed page is a bounded fetch of the most recent entries from the inbox.

Takeaways

Part 1

What a feed entry is

Before the pipeline, fix the unit of work: a feed entry is a lightweight pointer, not the post itself. That distinction is what makes a million-follower post survivable.

  1. 1
    A pointer, not a copy

    When a post lands in a follower's feed, what is stored is not the full post — it is a pointer: the post's id, a timestamp, and enough to render a row. The heavy content, the media, the author's profile, is fetched separately and cached. A feed is a list of pointers.

  2. 2
    Follows define the graph

    Who sees a post is decided by the follow graph: a user's feed is the union of the posts of the accounts they follow. That graph is the fan-out's destination set, and its shape — a few hundred edges for most, millions for a few — is what the design has to absorb.

  3. 3
    The design question

    Everything reduces to one question: when a post is created, do we write it into every follower's feed now, or do we assemble each follower's feed when they open it? The answer is the read/write fan-out decision, and the rest of the chapter is how we live with whichever we pick.

Part 2

The fan-out decision

Push writes a post into every follower's inbox at post time; pull assembles the feed at read time. Neither is free, and the honest design uses both, each where it wins.

  1. 1
    Push: build the inbox ahead of time

    Under push, the moment a post is stored, a worker writes a pointer into each follower's inbox. Reads become a trivial fetch of an already-built list. The cost is at write time, and it is proportional to the follower count — cheap for a normal user, catastrophic for a mega-follower.

  2. 2
    Pull: assemble at read time

    Under pull, the post is stored once and nothing else. When a user opens their feed, the system fetches the recent posts of everyone they follow and merges them. Writes are trivial — including for a mega-follower — but every read now does a merge across the follow set, which is expensive at a hundred million feeds.

  3. 3
    The honest answer: both

    Real systems split by follower count. Normal users get their feeds pushed, so their reads are trivial. Mega-followers get pulled: their posts are not written into two million inboxes; instead, a follower's feed fetches their recent posts at read time and merges them in. The write-time cost is bounded, and the read-time cost only falls on the small set of people who actually follow a mega-account.

Part 3

The write path

A post is created, stored, and handed to a worker that fans it out to the right inboxes. The poster's response does not wait for the fan-out to finish.

  1. 1
    Store the post first

    The feed API validates the post, assigns it an id and a timestamp, and stores it in the post store. At this point the post exists and is immutable. Everything that follows — fan-out, media processing — is downstream of this one durable write.

  2. 2
    Enqueue the fan-out

    Instead of fanning out inline, the API enqueues a fan-out job and returns to the poster. The poster sees 'posted' in a few milliseconds; the worker does the slow, large fan-out in the background. This is what makes a two-million-follower post not freeze the post button.

  3. 3
    Fan out by strategy

    The worker reads the author's follower count. Below a threshold it pushes: it writes a pointer into each follower's inbox. Above it, it does nothing per-follower — the mega-account's posts will be pulled in at read time instead. One post, two strategies, chosen by a single number.

Part 4

The read path and pagination

Opening a feed is a fetch of the viewer's pre-built inbox, a merge in for any mega-followers, and a stable cursor so scrolling never skips or repeats a post.

  1. 1
    Fetch the inbox, not the graph

    The viewer opens the feed. The API reads their inbox — the list of pointers that was built by push — and returns the most recent page. For a normal user this is a single fast read of a pre-built list, which is why the feed feels instant.

  2. 2
    Enrich and merge the mega-followers

    The pointers are hydrated: each post's media ref is resolved to a CDN URL, and any posts from mega-followers — which were not pushed — are fetched and merged into the page. The client gets a fully-renderable feed from what was, at rest, a thin list of ids.

  3. 3
    Page with a cursor, not an offset

    Scrolling asks for the next page. The cursor is the timestamp and id of the last entry seen, so the next fetch is 'everything older than this'. An offset would skip posts when new ones land at the top and repeat them when the list shifts; a cursor tracks the data itself and stays stable.

Part 5

The media pipeline

A post's media is a separate problem: a large upload, a processing step, and a CDN in front. The feed stores a reference; the bytes travel a different path entirely.

  1. 1
    Upload direct to the store

    The client does not push a photo through the feed API. It asks the upload service for a signed URL and uploads the bytes straight to the object store. That keeps large media off the request path of the feed, and lets the store scale independently of the feed tier.

  2. 2
    Process into the sizes we serve

    The raw upload is never served as-is. A processor transcodes video and resizes images into the handful of sizes the product actually shows. The result is a set of processed artifacts, each addressed by a stable URL, and the original is kept for reprocessing.

  3. 3
    Serve from the edge

    When a feed is rendered, each media ref is resolved to a CDN URL. The viewer's browser fetches the image or video from the edge, not from the origin. The feed API never moves a single byte of media — it only ever hands out the URL that points at it.

Part 6

Ordering what is already there

The feed has the right posts; now they need the right order. Ranking is a scoring pass over the pre-built inbox, not a change to the write path.

  1. 1
    Score, then sort

    A ranking pass assigns each entry in the page a score from a handful of factors — recency, how the viewer engaged with this author before, whether the post is media — and sorts the page by that score. The set of posts is unchanged; only their order is.

  2. 2
    Why rank at read, not write

    Ranking is a read-time step because it is personal: the same post orders differently in two viewers' feeds. If it were baked in at write time, the fan-out would have to store a different order per follower — which is exactly the per-follower write cost we spent the whole fan-out section avoiding.

  3. 3
    The trade-off accepted

    A ranked feed is no longer strictly chronological, and some users prefer the reverse. That is a product choice layered on top of the same machinery: the write path builds the inbox, the read path fetches it, and ranking is the last, cheap, personal pass over a page of twenty.

★ Finale

End to end

One post, a crowd of followers: it is stored, fanned out to the right inboxes, fetched and merged on the other side, with the media riding a separate edge path.

  1. 1
    The whole system

    Every piece in one frame. A poster's post is stored and fanned out to follower inboxes; a viewer opens their feed, which is fetched from their inbox, merged for mega-followers, and hydrated with media from the CDN.

  2. 2
    A normal post, pushed

    A user with a few hundred followers posts. The API stores it, the poster is acknowledged, and the worker writes a pointer into each of those few hundred inboxes. A moment later, each of those followers sees it at the top of their feed without any extra work from them.

  3. 3
    A mega-post, pulled

    An account with two million followers posts. Nothing is written into two million inboxes — that would be the write explosion the design exists to avoid. Instead, the post is stored once, and each of the two million followers pulls it in when they open their feed.

  4. 4
    Opened, merged, served

    A follower opens their feed. The API fetches their pre-built inbox, merges in the recent posts of the mega-accounts they follow, hydrates each entry with its media URL, ranks the page, and returns it. The whole read is a fetch plus a merge — the write-time fan-out did the heavy lifting long ago.

🌐 In the wild

In the wild

Push/pull hybrid feeds are the dominant design in social products. The boxes below are anchored to the classes of well-known systems that run each piece — an illustrative mapping, not a claim about any one product's internals.

  1. 1
    The pattern, piece by piece

    Each box is a standard building block of a large social feed. Anchoring them to the classes of production systems that run that piece turns the abstract pipeline into 'the shape behind the feeds you scroll'.

  2. 2
    Why the same split keeps winning

    Independent social products converge on the same hybrid because each piece removes a real failure: the push side removes the read-time join, the pull side removes the mega-follower write explosion, the cursor removes pagination drift, and the media pipeline removes origin load. That convergence is the evidence the design is load-bearing.