# Design a News Feed (Instagram, Twitter, LinkedIn)

> Build a personalised feed with fan-out on write, fan-out on read or a hybrid, feed caching, ranking and pagination. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/system-design/case-news-feed
Last updated: 2026-11-28

Build a personalised feed with fan-out on write, fan-out on read or a hybrid, feed caching, ranking and pagination.

Advanced · about 5 hours · difficulty 4/5

Learn first: [Event Streaming with Kafka](https://www.internhack.in/roadmaps/tracks/system-design/kafka-event-streaming), [Redis in Practice](https://www.internhack.in/roadmaps/tracks/system-design/redis-in-practice), [Sharding and Partitioning](https://www.internhack.in/roadmaps/tracks/system-design/sharding-partitioning)

A news feed shows each user recent posts from people they follow, ranked. The core question is **when** to assemble each user's feed.

### Requirements

- Users post (text, images); users follow others.
- Home feed shows followed users' posts, newest or ranked, with infinite scroll.
- Feed load in a few hundred ms; posting is fast; heavy read ratio.

### Fan-out on write (push)

When a user posts, push the post ID into every follower's precomputed **feed cache** (a Redis list or sorted set per user). Reading is a simple cache lookup: very fast. Cost: a celebrity with 5 crore followers triggers 5 crore writes per post, and you do work for inactive users.

### Fan-out on read (pull)

At read time, fetch recent posts from everyone the user follows and merge. No write amplification, but reads are slow and expensive for users who follow thousands.

### Hybrid (what real systems do)

Push for normal users; for **celebrities** (followers above a threshold), skip fan-out and merge their recent posts in at read time. Also skip pushing to long-inactive users and rebuild their feed on return.

### Components

- **Post service** stores posts (sharded by post ID or author); media in object storage plus CDN.
- **Graph service** stores follow relationships (sharded by user).
- **Fan-out workers** consume PostCreated events from Kafka and update feed caches.
- **Feed service** reads the cached post IDs, merges celebrity posts, hydrates them (author, counts) from caches, applies **ranking**, and returns a page with a **cursor**.
- Like and comment counts are updated asynchronously and cached; approximate counts are fine.

### Ranking

Start with reverse chronological. Ranked feeds score candidates on affinity, engagement, recency and content type, often with an ML model. Keep candidate generation and ranking as separate stages.

### Pitfalls

- Pure fan-out on write and the celebrity problem.
- Offset pagination on a constantly changing feed.

You are ready to move on when you can compare push, pull and hybrid with numbers and explain how a celebrity's post reaches followers' feeds.

## Key concepts

- **Fan-out on write**
- **Fan-out on read**
- **Hybrid and the celebrity problem**
- **Feed cache in Redis**
- **Post hydration**
- **Feed ranking stages**
- **Cursor pagination**
- **Social graph storage**

## Mini project

Write a design doc and build a prototype with users, follows and posts in Postgres, a Kafka or queue-based fan-out worker writing post IDs to Redis feeds, and a celebrity threshold that switches to pull. Simulate one celebrity with 1 lakh followers and compare write load.

## Check yourself

Why does pure fan-out on write break for celebrity accounts, and how does a hybrid approach fix it without slowing everyone's feed?

## Free resources

- [Engineering at Meta (Instagram, WhatsApp)](https://engineering.fb.com/) (Meta)
- [TAO: Facebook's distributed data store for the social graph](https://www.usenix.org/conference/atc13/technical-sessions/presentation/bronson) (USENIX)
- [The System Design Primer (Twitter timeline solution)](https://github.com/donnemartin/system-design-primer) (GitHub)

Previous: [Design a Chat App (WhatsApp)](https://www.internhack.in/roadmaps/tracks/system-design/case-chat-app) · Next: [Design a Video Streaming Platform (YouTube, Hotstar)](https://www.internhack.in/roadmaps/tracks/system-design/case-video-streaming)

## More in HLD Case Studies: Large Products

- [Design a Chat App (WhatsApp)](https://www.internhack.in/roadmaps/tracks/system-design/case-chat-app)
- [Design a News Feed (Instagram, Twitter, LinkedIn)](https://www.internhack.in/roadmaps/tracks/system-design/case-news-feed)
- [Design a Video Streaming Platform (YouTube, Hotstar)](https://www.internhack.in/roadmaps/tracks/system-design/case-video-streaming)
- [Design Ride Matching (Uber, Ola, Rapido)](https://www.internhack.in/roadmaps/tracks/system-design/case-ride-matching)
- [Design a Payment System (UPI-style)](https://www.internhack.in/roadmaps/tracks/system-design/case-payments-upi)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [System Design Roadmap](https://www.internhack.in/roadmaps/tracks/system-design)
