Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
How a social feed works: fan-out on write vs fan-out on read, the celebrity problem, candidate generation, ranking models, caching and pagination.
Quick answer: A social feed is built in two stages. First the system gathers candidates: recent posts from accounts you follow, plus recommended posts. It does this either by pre-computing a list for each user when someone posts (fan-out on write) or by collecting posts at the moment you open the app (fan-out on read), and large platforms combine both. Then a ranking stage uses machine learning models to predict how likely you are to like, comment on, share or linger on each candidate, and orders the feed by those predictions. Heavy caching makes the result appear instantly.
This article describes the standard architecture for large social feeds. Instagram has publicly explained the kinds of signals it ranks on; its exact systems are not public and evolve constantly.
When you open the app, the service must pick a few dozen posts for you out of everything posted by the accounts you follow, and increasingly from accounts you do not. It must do this in a few hundred milliseconds, for hundreds of millions of people, many times a day.
The workload is extremely read-heavy: people scroll far more often than they post.
Build the feed when the user asks for it.
| Pros | Cons |
|---|---|
| Posting is cheap: one write | Reading is expensive: hundreds of lookups per request |
| No wasted work for inactive users | Slow for users who follow many accounts |
| Always fresh | Hard to keep fast under load |
Do the work when someone posts.
| Pros | Cons |
|---|---|
| Reads are very fast | Posting triggers one write per follower |
| Simple read path | Wasted work for followers who never open the app |
| Storage for a list per user |
The fan-out itself is done asynchronously by background workers fed from a message queue, so the person posting does not wait.
Fan-out on write breaks down for accounts with tens or hundreds of millions of followers. One post would trigger a hundred million writes, delaying delivery and swamping the system.
The standard answer is a hybrid:
Systems also skip fan-out to users who have not been active recently and rebuild their feeds on demand.
Early feeds simply showed posts newest first. As people followed more accounts, most posts went unseen, so platforms moved to ranking by predicted interest.
Instagram has explained its approach in general terms in Instagram Ranking Explained. It describes using many signals, including:
From these, models make predictions, such as how likely you are to spend time on a post, like it, comment, share it, or tap through to the profile. The predictions are combined into a score, and posts are ordered by it. The company also notes that different surfaces (Feed, Stories, Explore, Reels) are ranked by different systems.
It is far too expensive to run a large model on every possible post. So ranking is a funnel, the same shape described in Google's paper on YouTube recommendations:
| Stage | Input | What it does |
|---|---|---|
| Candidate generation | Millions of posts | Cheaply select a few thousand: recent posts from followed accounts, plus recommendations |
| First-pass ranking | Thousands | A lightweight model narrows to a few hundred |
| Final ranking | Hundreds | A large model predicts several engagement outcomes per post |
| Re-ranking and filtering | Dozens | Apply rules: remove policy-violating content, avoid many posts in a row from one account, mix formats, insert ads |
Recommended content from accounts you do not follow is found by similarity: representing users and posts as vectors and retrieving posts close to your interests. See how recommendation systems work and how embeddings work.
Counters such as likes are updated asynchronously and can be slightly out of date. That is a deliberate choice of eventual consistency: nobody is harmed if a like count lags by a second.
Ranking for engagement is powerful and contested. Optimising only for predicted clicks can favour sensational content, so platforms add other objectives and constraints, offer chronological or "following" views, and provide controls for hiding or reporting content. How to weigh those goals is as much a product and policy question as a technical one.
When a user posts, the system immediately adds the post to each follower's precomputed feed, so reading the feed later is a single fast lookup.
They skip fan-out for those accounts and fetch their recent posts at read time, merging them into each follower's feed.
Most platforms rank posts by predicted interest using signals such as your past interactions and the post's popularity. Many also offer a chronological option.
New posts are added as they are fanned out or when you refresh. Counts and rankings are updated continuously but may lag slightly.
A feed is a pipeline: gather candidates cheaply, rank them carefully, cache the result, and serve it in pieces. The classic design tension is between doing the work at write time or read time, and the practical answer is a hybrid that treats ordinary and very large accounts differently. Ranking then decides what you see first, using predictions of what you are most likely to care about.