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

All system design examples