Design a news feed like Facebook's
hard 50 minShow each person the best recent posts from everyone they follow, in a fifth of a second.
Explain your choices
Answer first. Then compare your reasoning.
13 questions 0 got it 0 to review13 not marked
Summary
Trade-offs and cheat sheet
Decisions
| Decision | Choice | Because | Cost |
|---|---|---|---|
| Push or pull | Both, by followers | 2.3M against 116M, and uneven authors | Two paths |
| Feed entry | ID and time | One copy of each post | Hydration reads |
| Order | Ranked once a visit | Stable pages | Session storage |
| Write path | Durable, then queue | The author does not wait | Seconds of delay |
| Follow data | Two partitioned tables | One-step questions | Every edge written twice |
| Consistency | Eventual, own posts at once | Nobody compares feeds | Counts are old |
| Privacy | Checked at read | Copies lie | Work on each read |
| Updates | Small hints on a stream | 16.7M polls saved | Open connections |
When they push back
| They say | Answer with |
|---|---|
| "Why 10,000?" | "It is where one post costs a worker about a second. I would measure delivery delay and move it." |
| "Use a graph database." | "The feed asks one-step questions, which two key lookups answer. I would add one for friend suggestions." |
| "Just cache the whole feed reply." | "Then a deletion or block stays visible. I cache IDs and posts separately and check on read." |
| "Can't users see posts instantly?" | "Yes, for a price: no batching, and hints to 500 million streams. Ten seconds costs far less. Which would the product choose?" |
| "Isn't 25 TB of memory expensive?" | "Yes. Options: keep 200 IDs, keep only 3 days active, or pull for rarely seen users. Each lowers cost and raises rebuilds." |