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.
Numbers that decide
Work out a number when the answer changes what you build.
Capacity
The two products that decide
Traffic
Push against pull
Ready feeds
All the numbers
| Quantity | Working | Result |
|---|---|---|
| New visits | 3 × 2B / 86,400 | 69,000/s, 208,000 at peak |
| Candidates scored heavily | 69,000 × 100 | 6.9M/s, 21M at peak |
| Full posts shown | 231,000 × 20 | 4.6M/s, 14M at peak |
| One big post, one at a time | 10M × 1 ms | 10,000 s, nearly 3 hours |
| One big post at 1M inserts/s | 10M; 100M | 10 s; 100 s, if nothing else runs |
| Recent posts of big accounts | 1M accounts × 100 posts × 20 B | 2 GB: fits in every feed server |
| Ranked visit kept 10 minutes | 69,000 × 600 s × 1 KB | 42 GB, 125 GB at peak |
| Open connections | 25% of 2B, 100,000 a server | 500M, 5,000 servers |
| Polling instead | 500M / 30 s | 16.7M/s: 72 times the feed traffic |
| Fan-out workers | 6.9M / 10,000 inserts/s each | 694 at peak, so 1,024 partitions |
| Post text and fields | 400M × 1 KB | 400 GB a day, 730 TB in 5 years, 2.2 PB with 3 copies |
| Images | 70% of posts × 200 KB | 56 TB a day, 20 PB a year |
| Video | 20% of posts × 20 MB | 1.6 PB a day, 584 PB a year |
| Feed replies | 694,000 × 20 × 3 KB | 42 GB/s, 333 Gbps at peak |
| Images delivered | 694,000 × 70% × 10 × 200 KB | 972 GB/s, 7.8 Tbps at peak |
| Image traffic a month | a third of peak, 30 days | 0.84 EB; 0.01/GB |
So what?
The decision each number makes
| Number | Decision | Would change if |
|---|---|---|
| 2.3M pushes against 116M pulls | Ready feeds, filled when people post | People post as often as they read |
| 10M followers: 10 s to 3 hours | Pull for big accounts | Follower counts are limited to a few thousand |
| 2 GB for all big accounts | Keep them in feed server memory | There are 100 times more big accounts |
| 14M full posts a second at peak | A post cache; at 99% hits the store sees 140,000/s | Pages show three posts |
| 25 TB of ready feeds | Only warm users, IDs only | Under 100 GB, one machine and a replica |
| 16.7M polls a second | Open streams with small hints | Only a few thousand are online |
| 7.8 Tbps of images | CDN; at 90% hits the origin serves 0.8 Tbps | Text only |
Latency budget (200 ms p99 at our servers)
| Step | Budget |
|---|---|
| Gateway: sign-in and limits | 10 ms |
| Ready feed and follow list | 15 ms |
| Merge big accounts, light pass | 5 ms |
| Headers for 100 candidates | 20 ms |
| Features and model | 60 ms |
| Hydrate 20 posts | 25 ms |
| Assemble and send | 15 ms |
| Reserve | 50 ms |