Lessons in this course (14)

10. Case study — news feed (social timeline)

Advanced★ Must knowLesson 10 of 14

Requirements: post, follow, see a feed of followed users' posts sorted by time; 100M DAU; feed load < 200 ms.

Two ways to build the feed:

Fan-out on write (push)Fan-out on read (pull)
HowWhen a user posts, insert the post id into each follower's feed list (Redis)When a user opens the feed, fetch recent posts from everyone they follow and merge
Read costVery fastSlow for users following many
Write costHuge for celebrities with millions of followersCheap

Hybrid (used by large networks): push for normal users; for celebrities, pull their posts at read time and merge.

text
Client → LB → Post service → Posts DB (sharded by post id) → event "PostCreated" → Fan-out workers → Redis feed lists (per user, last 500 ids)
Client → LB → Feed service → Redis feed list + celebrity posts → hydrate posts from cache/DB → media via CDN

Extras: pagination with cursors (not offsets), ranking service, counters for likes eventually consistent, notifications via a queue.