Social & content · Intermediate
News feed
Timeline with fan-out on write, a per-user feed cache and media on a CDN.
Every part, and why it is there
Users
People scroll far more than they post: roughly 100 feed reads for every new post. That ratio drives every choice here.
CDN
Serves images and video from servers near the user. Media is most of the bytes, and none of it needs to touch your API.
API gateway
One entry point for the apps: checks auth, rate-limits, and routes /feed and /posts to their services.
Feed service
Returns a user’s timeline. Because feeds are precomputed, this is mostly one cache read plus a batch fetch of post details.
Post service
Stores a new post and announces it. It does not update anyone’s feed itself, so posting stays fast however many followers you have.
Feed cache
Holds each active user’s list of recent post ids. Inactive users’ feeds expire and are rebuilt from the database when they return.
Posts DB
Source of truth for posts and follows. Read replicas absorb cache misses so the primary only takes writes.
New-post events
Decouples posting from fan-out. If fan-out falls behind, events wait here instead of slowing down posting.
Fan-out workers
For each new post, push its id into every follower’s cached feed. Work grows with follower count, so it runs in the background and scales out.
Media storage
Original photos and videos. The CDN pulls from here on a miss and keeps a copy at the edge.
Asked in interviews at
- meta
- doordash
- atlassian
Concepts used here
- Caching: Keep recent answers in memory so the database only does each piece of work once. Then deal with the three ways that goes wrong: stale data, a full cache, and a stampede.
Learn more
- Design FB News Feed System Design Interview w/ ex: Meta Senior Manager (Hello Interview)
- Designing INSTAGRAM: System Design of News Feed (Gaurav Sen)
- Design Scalable News Feed System Similar to Instagram, Facebook & Twitter | System Design (Irtiza Hafiz)
- Design Facebook's News Feed (Hello Interview)
- Design a news feed system (ByteByteGo)
- Timelines at Scale (Raffi Krikorian, Twitter) (InfoQ)