The short answer
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.
The problem
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.
Approach 1: Fan-out on read (pull)
Build the feed when the user asks for it.
- Look up everyone the user follows.
- Fetch each account's recent posts.
- Merge, sort and return the top results.
| 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 |
Approach 2: Fan-out on write (push)
Do the work when someone posts.
- A user publishes a post.
- The system looks up all their followers.
- It inserts the post's ID into each follower's precomputed feed list, usually kept in an in-memory store. See why Redis is fast.
- Reading the feed is now a single lookup of that list.
| 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.
The celebrity problem
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:
- For ordinary accounts, push posts to followers' feed lists at write time.
- For very large accounts, do not fan out. When a user opens their feed, pull recent posts from the few celebrities they follow and merge them with the precomputed list.
Systems also skip fan-out to users who have not been active recently and rebuild their feeds on demand.
From chronological to ranked
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:
- Your activity: what you have liked, saved, shared or commented on.
- Information about the post: how popular it is, when it was posted, its format and location.
- Information about the poster: how often people have interacted with them recently.
- Your history with that person: whether you comment on each other's posts, for instance.
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.
The ranking pipeline
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.
Serving it fast
- Feed cache. The ranked list of post IDs for each active user is cached. The first screen loads from cache while fresher content is fetched.
- Hydration. The feed list holds only IDs. A separate step fetches post details, author info, like counts and your relationship to each post, with heavy use of caches. See caching strategies.
- Media from a CDN. Images and video are served from edge servers; see how CDNs work.
- Cursor pagination. Infinite scroll asks for "the next 10 after this post", not "page 3". Offsets break when new posts arrive at the top and would cause duplicates or gaps.
- Prefetching. The app loads the next batch before you reach the bottom.
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.
Storage
- Posts and metadata live in sharded databases, partitioned by user.
- The social graph (who follows whom) is a specialised store optimised for "followers of X" and "accounts X follows".
- Media goes to object storage and is distributed through CDNs.
- Feed lists and counters live in in-memory stores.
The trade-offs in ranking
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.
Frequently asked questions
What is fan-out on write?
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.
How do feeds handle accounts with millions of followers?
They skip fan-out for those accounts and fetch their recent posts at read time, merging them into each follower's feed.
Why is my feed not in chronological order?
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.
Does the feed update in real time?
New posts are added as they are fanned out or when you refresh. Counts and rankings are updated continuously but may lag slightly.
Conclusion
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.
Related articles
- How Recommendation Systems Know What You Want to Watch
- Caching Strategies: Write-Through, Write-Back, and Cache-Aside
- How Message Queues Like Kafka Decouple Systems
- How Redis Is So Fast
- How Uber Matches Riders With Nearby Drivers
