How to Build a Social Media Feed That Scales
A social media feed that scales usually combines two approaches. For most users, posts are pushed into followers' feeds when they are created (fan-out on write). For accounts with huge follower counts, posts are pulled i
A social media feed that scales usually combines two approaches. For most users, posts are pushed into followers' feeds when they are created (fan-out on write). For accounts with huge follower counts, posts are pulled in when a follower opens the app (fan-out on read). Store feeds in Redis sorted sets, page through them with cursors instead of page numbers, and run ranking and moderation as separate steps. This hybrid model keeps feeds fast without overloading your system when a popular account posts.
Why Is the Feed the Hardest Part of a Social App?**
Profiles, likes and comments are fairly simple. The feed is different. Every time someone opens the app, you need to show the most relevant recent posts from hundreds of accounts they follow, in a few hundred milliseconds, while millions of other users do the same.
There are two classic ways to build it, and each one breaks in a different place.
Option 1: Fan-Out on Read (Pull)
When a user opens their feed, the server looks up everyone they follow, fetches recent posts from each, merges them and sorts them.
Pros: writes are cheap, and new posts appear instantly.
Cons: reads are expensive. A user following 1,000 accounts triggers 1,000 lookups every time they refresh.
Option 2: Fan-Out on Write (Push)
When someone posts, the server copies the post ID into the feed of every follower. Reading a feed becomes one quick lookup.
Pros: reads are very fast.
Cons: writes explode for popular accounts. One post from an account with 5 million followers means 5 million feed updates.
The Hybrid Model Most Large Apps Use
- Normal accounts: fan-out on write. Their posts go straight into followers' feeds.
- High-follower accounts: fan-out on read. Their posts are fetched and merged when a follower loads the feed.
A follower threshold (for example, 10,000 or 100,000 followers) decides which path an account uses. You tune it based on your traffic.
Storing Feeds in Redis Sorted Sets
Redis sorted sets fit feeds well: each member is a post ID, and the score is the timestamp (or a ranking score). Here is a fan-out on write with a size cap, using Node.js and ioredis:
import Redis from "ioredis";
const redis = new Redis(process.env.REDIS_URL);
const FEED_LIMIT = 800; // keep only the newest 800 items per feed
export async function fanOutPost(post, followerIds) {
const pipeline = redis.pipeline();
for (const followerId of followerIds) {
const key = `feed:${followerId}`;
pipeline.zadd(key, post.createdAt, post.id);
// Remove everything except the newest FEED_LIMIT items
pipeline.zremrangebyrank(key, 0, -(FEED_LIMIT + 1));
}
await pipeline.exec();
}
For large follower lists, run this in a background worker and process followers in batches, so posting stays fast for the author.
Paginate With Cursors, Not Page Numbers
Page numbers break in feeds because new posts keep arriving. If a user is on page 2 and ten new posts arrive, page 3 shows duplicates. Cursor pagination fixes this by asking for "posts older than the last one I saw":
export async function readFeed(userId, cursor = "+inf", limit = 20) {
const results = await redis.zrevrangebyscore(
`feed:${userId}`,
cursor,
"-inf",
"WITHSCORES",
"LIMIT", 0, limit
);
const items = [];
for (let i = 0; i < results.length; i += 2) {
items.push({ postId: results[i], score: Number(results[i + 1]) });
}
const last = items[items.length - 1];
// "(" makes the next query exclusive, so the last item is not repeated
const nextCursor = last ? `(${last.score}` : null;
return { items, nextCursor };
}
One catch: if two posts share the same timestamp, an exclusive cursor can skip one. Use timestamps in milliseconds, or add a tiebreaker such as a sequence number to the score.
Merging High-Follower Posts at Read Time
For accounts that skip fan-out, keep a separate sorted set of their recent posts (posts:{authorId}). When a user loads their feed:
- Read their pre-built feed (from fan-out on write).
- Read recent posts from the high-follower accounts they follow.
- Merge both lists by score and return the top items.
Cache this merged result for a short time (for example, 30 to 60 seconds) to avoid recomputing it on every pull-to-refresh.
Ranking: Chronological vs. Relevance
Chronological feeds are simple and transparent. Ranked feeds usually increase engagement, but they need more work:
- Collect signals: likes, comments, shares, dwell time, relationship strength
- Score candidate posts in a ranking service
- Re-rank the top few hundred candidates, not the whole feed
- Keep a "Latest" option, because many users want to see posts in order
A practical path is to launch chronological, collect signals for a few months, then add ranking once you have real data.
Moderation Must Sit Next to the Feed
A feed that scales without moderation also spreads harmful content faster. Build these in early:
- Automated checks for images and text before or right after posting
- A review queue for flagged content
- Report, block and mute tools for users
- A way to remove a post from all feeds at once (store post IDs in feeds, never full copies, so deleting the original post removes it everywhere)
Apple and Google both require reporting and blocking tools in apps with user-generated content, so these are not optional for app store approval.
When Should You Bring In Help?
If you are building a feed for a new community or creator app, the patterns above will take you far. When you also need chat, live video, moderation tooling and monetization, working with an experienced social media app development company can save months of trial and error.
"Feeds rarely fail on day one. They fail the day your first big creator joins. Design for that day before it arrives."
Tarun Nagar, Founder and CEO, Dev Technosys
Social Media App Development Partners Worth Considering
The company details below come from each company's public information and are self-reported, so confirm them directly before signing anything.
1. Dev Technosys
Dev Technosys builds social and community apps end to end: profiles, feeds, real-time chat, live video, creator monetization and admin moderation tools. Its work on on-demand, dating and streaming platforms shows in how it plans fan-out, caching and moderation queues before launch day. It supports iOS, Android and web, with scaling help as communities grow. One limitation: large human moderation teams are outside its scope, so clients plan their own review staff.
2. Tata Elxsi
Tata Elxsi, headquartered in Bengaluru, combines design and technology services across media, transportation and healthcare. Its media and design background is useful for social platforms where user experience and content presentation drive engagement. It usually works on larger, structured programs rather than quick MVPs. Tata Elxsi suits media companies building social or community features into their content platforms.
3. Sopra Steria
Sopra Steria, headquartered in Paris, provides consulting, digital services and software development for large European organizations. Its experience with secure, regulated systems helps social platforms that must meet strict European privacy and online safety rules. Its focus is enterprise programs, so early startups may find it heavy. Sopra Steria suits European organizations launching community platforms with strong compliance needs.
4. Tietoevry
Tietoevry, headquartered in Espoo, Finland, delivers software and cloud services with a strong presence in the Nordic countries. Its cloud and data skills fit community apps that need reliable infrastructure and analytics for growing user bases. Its client base is mainly Northern European. Tietoevry suits Nordic media groups and organizations building community or social platforms for local audiences.
5. Mastek
Mastek, headquartered in Mumbai, offers digital engineering, cloud and data services with a strong client base in the UK and US. Its data and cloud work helps social platforms that need better analytics, recommendation data pipelines and cloud scaling. Consumer app design is not its main strength. Mastek suits companies that already run a social product and need data platforms and cloud modernization behind it.
FAQs
Should a new social app start with fan-out on write or read?
For a new app with small follower counts, fan-out on write is simpler and gives fast reads. Add the hybrid model when some accounts grow large.
Is Redis enough to store all feeds?
Redis works well for the recent part of each feed. Keep the full post data and older history in a primary database, and rebuild feeds from there if needed.
How many items should a feed keep?
Many apps keep a few hundred recent items per user in the fast store. Older content is fetched from the main database when users scroll far back.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.