System Design Visualized
Chapter 11 · about 40 minutes

Design a News Feed System

A news feed is the ever-changing stream of posts you see when you open the app: status updates, photos, videos and links from the people and pages you follow. Facebook's news feed, Instagram's feed and Twitter's timeline are all versions of this question.

Start the interactive chapter
  1. 11.1Requirements and APIsMobile app and web A user can publish a post and see friends' posts on the news feed page Sorted in reverse chronological order (for…
  2. 11.2High-level design: publishing and buildingFeed publishing Web servers: redirect traffic to internal services, and enforce authentication and rate limiting (only signed-in users with…
  3. 11.3Fanout on write vs fanout on read📤 Fanout on write (push) The feed is pre-computed at write time: a new post is delivered to friends' caches right after publishing. ✅…
  4. 11.4Deep dive: the fanout serviceFetch friend IDs from the graph database. Graph DBs are well suited to friend relationships and recommendations. Get friends' info from the…
  5. 11.5Deep dive: news feed retrieval and the cache layersA user sends GET /v1/me/feed. The load balancer sends it to a web server. The web server calls the news feed service. The service gets a…
  6. 11.6Wrap upThere's no perfect design; it depends on the constraints. Talking points: Scaling the database: bigger machine or more machines, relational…