Start with the decision#
Choose where to pay fan-out cost. Fan-out-on-write precomputes recipient views when content changes; fan-out-on-read assembles them when a reader asks. The right answer follows audience size, read frequency, freshness, and skew.
Mechanism and state flow#
- Estimate writers, followers per writer, reader sessions, items per feed, and acceptable freshness.
- For ordinary publishers, write recipient inbox references asynchronously and make delivery idempotent.
- For very large publishers, retain source posts and merge them into feeds at read time.
- Use stable cursors and versions so retries do not duplicate or reorder items unexpectedly.
- Measure write amplification, feed build latency, stale entries, celebrity skew, and storage per strategy.
Concrete example#
A social feed with celebrity accounts
Most posts fan out into follower inboxes, making ordinary feed reads cheap. Posts from accounts with millions of followers remain in an author stream and are merged into each reader's feed at request time.
Architecture consequence: Use a hybrid threshold because one global strategy pays the worst cost for the most skewed users.
Trade-offs#
| Option | Choose when | Cost or limit |
|---|---|---|
| Fan-out on write | Readers are frequent and publisher audiences are bounded. | Write amplification, stale inbox entries, and celebrity spikes. |
| Fan-out on read | Writes are frequent, reads sparse, or audiences enormous. | Read latency and multi-stream ranking work grow. |
| Hybrid | Audience size and activity are heavily skewed. | Two paths complicate ordering, caching, and diagnosis. |
Failure diagnosis#
- Failure
- A celebrity post enqueues millions of inbox writes into the same worker pool.
- Impact
- Ordinary users' posts and feed freshness are delayed behind one amplified event.
- Detection
- Queue age, fan-out cardinality, and per-author work show one source dominating capacity.
- Mitigation
- Switch high-cardinality authors to read-time merge, isolate fan-out tiers, and cap per-source scheduling.
- Trade-off
- Hybrid reads spend more compute and can expose ordering differences between paths.
Design checkpoint#
Work the scenario before revealing the checklist
- Estimate writes per post and reads per session for ordinary and celebrity users.
- Choose the threshold that moves a publisher to read-time merge.
- Define ordering across precomputed and read-time sources.
- Describe deletion and privacy propagation through both paths.
Use these prompts to extend the design. The useful answer is a reasoned change, not a memorized sentence.
- Where is ranking performed?
- How quickly does an unfollow remove content?
- How does a retry avoid duplicate inbox entries?
- What happens when a user follows ten celebrity accounts?
Related practice problems
Use the manifest-backed prompts below to apply this lesson in a complete design.
- Overview of the Pub/Sub serviceGoogle Cloud Documentation
- Caching challenges and strategiesAmazon Builders' Library
Sources reviewed 2026-09-04. Service limits and product-specific guarantees still require current verification.