- Alan opens the app and the app calls the
GET /get-feedendpoint. - The server reads the
followstable to determine who Alan follows. The query returns 300 accounts. - The server queries the
poststable for recent posts by those 300 accounts (one lookup per account, or equivalent aggregated query). - The server gathers a few hundred posts in memory, sorts them by timestamp, keeps the newest 50, and returns those 50 posts to Alan’s app.
- Read the
followstable (one read per feed open). - Perform many lookups to retrieve posts for each followed account (in this example ~300 lookups per feed open).
- Sort and truncate results in memory on each request.
If we receive 600 feed opens per second, that becomes:
- 600 reads of the
followstable per second, and - 600 × 300 = 180,000 post lookups per second.
GET /get-feed simply reads Alan’s stored feed (fast, single read) and returns the precomputed list.
The push (fan-out-on-write) approach trades increased write work and storage for much cheaper, predictable reads and lower read latency. Precomputing timelines is ideal when reads far outnumber writes, because it eliminates per-read aggregation and sorting.
Fan-out-on-write can cause write amplification for very large accounts (e.g., celebrities with millions of followers). For such cases, consider hybrid strategies: lazy fan-out (mix of push + on-read for large fans), per-actor sharding, caching layers (CDN or in-memory caches), or using separate “fanout” queues and background workers to smooth spikes.
- For most social feeds at scale, precomputing timelines (fan-out-on-write) provides predictable low-latency reads and much less load on the read path.
- Carefully evaluate tradeoffs: increased write work, storage, and operational complexity versus the benefits on the read path.
- For extremely large follower graphs adopt hybrid patterns and use batching, background workers, and rate limiting to control write amplification.
- Kubernetes Basics
- Designing Data-Intensive Applications — Feed Systems (concepts)
- [Fan-out patterns and considerations — blog posts and case studies]