Skip to content
SD-15 · Back to the write-up

Design a News Feed

Push post ids into cached timelines for most authors, pull celebrities at read time, then hydrate and rank from a post cache.

Follow a request

Clients
Gateway and graph
Read and write
Feeds and fan-out
Media CDNPhotos, video
ClientsApps and web
Social graphFollowers
API gatewayAuth + limits
Post serviceCreate, delete
Feed serviceGather, rank
Post cachePosts by id
Post store64 shards
Feed cache300 ids per user
Fan-out workersPush ids
Post eventsChange stream
1client → gateway · GET /v1/feedSam opens the app.1 / 9

The numbers, at a glance

For every post written……there are about 20 feed loads
1 post ≈ 1,740/s20 feed loads ≈ 35,000/s
Fan-out writes at peak5,000 posts a second
Few accounts are celebrities≈ 50,000 of 300 million authors
Yet without the hybrid they cause most of the fan-out writes.

A feed load, in order

Timeline read, celebrity pull, hydration and ranking. Fan-out happened earlier, when each post was written.

Client
API gateway
Feed service
Feed cache
Social graph
Post cache
Post store
1 GET /v1/feed
2 feed for user
3 read 300 ids
4 ids
5 celebs followed
6 4 accounts
7 recent ids + multi-get ≈ 500
8 load 5% misses
9 posts
10 post objects
11 20 ranked + cursor
12 200 feed
RequestResponseAsync, does not block

Push, pull or both

The decision this question is really about.

Pull on read
Too slow
GET /v1/feed
posts of 200 accounts
merge by time, p99 over 200 ms
+ Cheap writes.− 200 queries per feed load.
Push on write
Breaks on celebrities
POST
id → every follower’s timeline
3M writes/s at peak
+ One read per feed.− 50M writes for one celebrity post.
Hybrid
Our pick
Push: authors under 100K followersPull: celebrities
Merge + hydrate + rank
+ Fast reads, bounded writes.− Two paths to merge.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 1,000 loads/sMake it work
Clients
API gateway
Feed servicePost service
Social graphPost database
Build each feed on read from the post store.
Stage 2 · ≈ 20,000 loads/sPrecompute feeds
Clients
API gateway
Feed servicePost service
Feed cachePost storePost events
Social graphFan-out workers
Fan-out on write into a timeline per user.
Stage 3 · ≈ 100,000 loads/sHandle celebrities
Clients
API gateway
Feed service + celebrity pullPost service
Feed cachePost cachePost store
Social graphFan-out workersPost events
Pull celebrity posts at read time; hydrate from a post cache.
Stage 4 · 100,000 ranked loads/sRank and serve media
ClientsMedia CDN
API gateway
Feed service + rankingPost service
Feed cachePost cachePost store
Social graphFan-out workersPost events
Score about 500 candidates; media from a CDN.
Was this walkthrough useful?Your vote tells us what to improve next.