code.davidloor.com

Open prompt · 45 min recommended

Design a News Feed

00:00

Target 45:00

Design a News Feed

You have 45 minutes. Sketch the system in this notes pane.

Scope

Functional requirements

Non-functional requirements

Out of scope

Suggested approach

  1. Clarify requirements — number of users, average follows per user, expected celebrity (high-follower) accounts, acceptable staleness
  2. High-level design — a Post Service, a Follow Service (social graph), a Feed Service, and a cache tier
  3. API + data modelPOST /posts, GET /feed?user_id=&cursor=; posts table (post_id, author_id, body, created_at); follows table (follower_id, followee_id)
  4. Storage + caching — feeds are expensive to compute on demand; pre-compute (fan-out on write) or compute lazily (fan-out on read); cache the top N posts in each user's feed in Redis
  5. Bottlenecks + mitigations — celebrities with millions of followers make fan-out on write prohibitively slow; pagination and cursor-based feeds; cache stampede on popular users

Reference talking points

Your notes

Saved locally · 0 chars