Part 5 · Blueprint 25
Distributed News Feed Architecture
15 min reading · Sources · Editorial review pending
Precomputed timelines reduce reads but amplify work for prolific or popular publishers.
Page details
Published date · Last edited:
Draft edition. Editorial review and supplementary reading recommendations are still being completed.
Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Distributed Caching & Stampede Prevention, Message Queues & Event Streams: Kafka vs. RabbitMQ, Database Sharding & Consistent Hashing.
Sixty-second mental model
Problem: Precomputed timelines reduce reads but amplify work for prolific or popular publishers.
Use: Choose fan-out policy under skew and preserve pagination meaning.
Design boundary: Generate a chronological home feed from followed publishers. Keep post history authoritative and feed materialization disposable/rebuildable. Start with pull-on-read; add selective fan-out only when measured read work justifies it. Exclude opaque recommendation ranking in the first version.
Layer 1 · Intuition
Hypothetical scenario: Northwind is designing news feeds. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one feed item means and which component owns the post and eligibility records.
Think of personal reading trays filled from subscribed publishers. Separate the requester from post and eligibility records, then identify the retained evidence needed after failure.
- Authority
- The entitled state owner.
- Invariant
- A rule preserved across concurrency and failures.
Architecture and worked reasoning
Design boundary: Generate a chronological home feed from followed publishers. Keep post history authoritative and feed materialization disposable/rebuildable. Start with pull-on-read; add selective fan-out only when measured read work justifies it. Exclude opaque recommendation ranking in the first version.
Responsibilities on the request path
Domain interface and access patterns
POST /posts → post_id, visibility_version; GET /feed?cursor=... → items, next_cursor
posts(author_id, post_id, creation_order, visibility_version, state); follows(reader_id, publisher_id); timeline(reader_id, creation_order, post_id). Index timeline by reader and stable order; one post identity deduplicates push/pull overlap.
Workload and limiting resource
Choose 1,000 posts/s and 200 followers/post: eager fan-out creates 200,000 timeline writes/s before retries. A celebrity with 10,000,000 followers posting once creates ten million obligations by itself. If a worker pool sustains a hypothetical 50,000 timeline writes/s, that one post needs at least 200 seconds with no competing work. Hybrid fan-out can reduce this write burst at the cost of read-time merging.
Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.
Mutation or publication path
- Commit a post identity and visibility version.
- Materialize eligible follower references for selected publishers.
- Record fan-out progress so retries do not duplicate entries.
Observation and recovery path
- Read a stable cursor from the home timeline.
- Check current visibility and retrieve post content.
- Merge high-fan-out publishers under a bounded pagination rule.
Failure that changes the decision
Hypothetical scenario: A publisher changes from push to pull while readers paginate. Preserve a migration boundary and deduplicate by post identity; timestamp-only pagination can skip or repeat equal-time entries.
Attempt this decision before reading the explanation
Can a deleted post be safely returned because its timeline entry still exists?
No. A materialized reference does not override current visibility. Remove or tombstone the authoritative post and enforce the permitted visibility/freshness rule while cleaning projections asynchronously.
Supporting mechanism analysis
Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.
Hypothetical scenario. Priya needs an activity feed of catalogue changes, while one busy supplier produces far more updates than the rest.
In short. Keep item authority separate from reader projections. Isolate high-fan-out publishers and bound the serving merge.
Hypothetical scenario. A professional community shows posts from followed authors. Most authors have modest audiences, but a few have many followers. Readers expect stable pagination, and a deleted post must stop appearing through new requests under a declared withdrawal policy. A reverse-chronological list is the first release; personalized ranking is a later change.
The core state is posts, follow relationships and visibility decisions. A reader's assembled feed is derived state. Its freshness and completeness can differ from the authoritative post record, but those differences must be intentional. A cache hit cannot establish that the reader is still permitted to see an item.
Scope includes posting, following, pagination, visibility and derived-view recovery. Advertising auctions, video transcoding and recommendation training are excluded. This case studies fan-out and read assembly rather than promising a universal social platform.
Fan-out-on-write appends a reference into recipient inboxes when a post is created. It makes some reads inexpensive but multiplies write work by recipients and requires handling follow changes and deletion. Fan-out-on-read stores author histories and assembles a reader's view later, shifting work toward reads.
Neither is always better. A quiet reader may never consume eagerly prepared entries. A highly active reader may repeatedly need expensive merge work. A publisher with a large audience can dominate fan-out while contributing little post volume.
Do not use one average follower count to hide that distribution. Identify hot publishers, active-reader fractions, retention and the freshness expected for new follows. Those inputs determine whether a mixed strategy is useful.
Write a post under a stable identity and author authority. Record publication intent with the authoritative change. Projection workers append deduplicated references to eligible recipient inboxes. They preserve the source post version so retries and older updates do not recreate withdrawn content.
A read merges the selected sources under an explicit ordering rule, removes duplicates and checks visibility. Use a deterministic tie-breaker, such as an agreed creation order plus unique identity. If ordering changes between pages, define whether the cursor pins a snapshot or permits bounded movement.
A hybrid design may retain ordinary author fan-out while reading selected high-fan-out histories directly. That requires one coherent merge contract. Calling a publisher a special case does not eliminate authorization, freshness or pagination obligations.
A Northwind activity feed is a derived view, not the authoritative record of an item or its permissions. Postgres can own the item change while asynchronous workers maintain per-reader projections. Redis can serve a selected recent working set. Decide what the reader is promised about publication, withdrawal and ordering before optimizing how quickly an inbox can be assembled.
In a hypothetical workload, ten thousand ordinary publishers each create two posts per day for one hundred recipients. Their projection work is 10,000 × 2 × 100 = 2,000,000 deliveries per day. A single large publisher with one million recipients and five daily posts creates 1,000,000 × 5 = 5,000,000 deliveries. The one large publisher therefore creates more projection work than the ordinary group in this model, despite having far fewer source posts.
A hybrid design can materialize ordinary activity and merge high-fan-out activity during a read. That change moves work between publication and serving; it does not eliminate it. Bound how many sources a read consults, preserve a stable merge order, and make repeated delivery of an event harmless under the chosen version rule. A source transaction that records a post and a projection job also needs a policy for the uncertain handoff to its dispatcher.
Deletion must reach the derived representations and remain effective during replay. A new worker rebuilding an inbox should not resurrect a withdrawn post from an older event. Keep the relevant version or tombstone evidence, apply current eligibility before serving, and define whether a reader can see a stale projection while withdrawal catches up. A fast Redis lookup cannot substitute for those rules.
For pagination, choose the history the cursor represents. A stable ordering key plus a tie-breaker gives the merge a defined position; a ranked feed can additionally need a ranking or snapshot version. Changing an offset into an opaque string does not create those semantics. First establish continuity for the small chronological view, then evaluate whether richer ranking justifies its extra evidence and rebuild requirements.
Hypothetical scenario. Choose 10,000 ordinary authors producing two posts daily with 100 recipient inboxes each. Logical posts are 10,000 × 2 = 20,000 per day. Projection appends are 20,000 × 100 = 2,000,000 per day, excluding retries and later relationship changes.
Now one publisher creates ten posts for 100,000 followers. Its fan-out alone is 10 × 100,000 = 1,000,000 references daily, half the ordinary group’s append work from only ten posts. That difference is why a single global average hides an important design choice.
Choose 32 bytes per logical reference. Three million daily references use 3,000,000 × 32 = 96,000,000 bytes, or 96 MB. Thirty days retain 2.88 GB of reference payload before indexes, replication and allocation. This is not the size of the original post bodies or a complete storage estimate.
For read assembly, suppose one page examines five author streams and requests 20 candidate references from each. It considers 5 × 20 = 100 candidates before filtering and deduplication, but returns at most 20. A visibility filter that removes many candidates may require another bounded fetch; it cannot promise a full page without more work.
A projection backlog of 120,000 references with 20,000 appends per minute of capacity and 10,000 new references per minute drains at 20,000 −10,000 = 10,000 per minute. Recovery takes 120,000 ÷ 10,000 = 12 minutes under constant successful processing rates. Cold reads during that interval need a declared fallback.
Primary evidence for northwind’s catalogue activity feed: HTTP reuse has explicit cache semantics relevant to withdrawal.
Offset pagination can shift when new posts arrive ahead of the offset. A cursor can encode the last ordering position and required snapshot context, but must be validated and bound to the appropriate reader and query. An opaque token does not automatically make pagination stable or authorized.
Layer 3 · Internals
Trade-offs and limits
| Approach | Provides | Requires |
|---|---|---|
| Fan-out on write | Prepares personalized read material before a viewer asks. | Popular publishers and eligibility changes amplify update work. |
| Fan-out on read | Defers composition until a viewer requests it. | Read cost and candidate fan-in grow with the followed set and ranking policy. |
Recovery decision
Hypothetical scenario: A publisher changes from push to pull while readers paginate. Preserve a migration boundary and deduplicate by post identity; timestamp-only pagination can skip or repeat equal-time entries.
No. A materialized reference does not override current visibility. Remove or tombstone the authoritative post and enforce the permitted visibility/freshness rule while cleaning projections asynchronously.
Write your design before revealing the review
Can a deleted post be safely returned because its timeline entry still exists?
Drafts and self-review are stored only in this browser. They are separate from reading completion.
Compare your decision
No. A materialized reference does not override current visibility. Remove or tombstone the authoritative post and enforce the permitted visibility/freshness rule while cleaning projections asynchronously.
A publisher changes from push to pull while readers paginate. Preserve a migration boundary and deduplicate by post identity; timestamp-only pagination can skip or repeat equal-time entries.
Check your understanding
Can a deleted post be safely returned because its timeline entry still exists?
No. A materialized reference does not override current visibility. Remove or tombstone the authoritative post and enforce the permitted visibility/freshness rule while cleaning projections asynchronously.
How would you recover from this failure: A publisher changes from push to pull while readers paginate. Preserve a migration boundary and deduplicate by post identity; timestamp-only pagination can skip or repeat equal-time entries.
Start with the exact boundary that failed. Commit a post identity and visibility version. Materialize eligible follower references for selected publishers. Record fan-out progress so retries do not duplicate entries. Then recover evidence through the observation path: Read a stable cursor from the home timeline. Check current visibility and retrieve post content. Merge high-fan-out publishers under a bounded pagination rule. Preserve the distinction between a confirmed state change and an unavailable response.
Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?
Choose 1,000 posts/s and 200 followers/post: eager fan-out creates 200,000 timeline writes/s before retries. A celebrity with 10,000,000 followers posting once creates ten million obligations by itself. If a worker pool sustains a hypothetical 50,000 timeline writes/s, that one post needs at least 200 seconds with no competing work. Hybrid fan-out can reduce this write burst at the cost of read-time merging. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Generate a chronological home feed from followed publishers. Keep post history authoritative and feed materialization disposable/rebuildable. Start with pull-on-read; add selective fan-out only when measured read work justifies it. Exclude opaque recommendation ranking in the first version.
Which component in this topology could be removed from a smaller first deployment?
Post store, Fan-out planner, Home timeline, Feed reader name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Commit a post identity and visibility version.
What evidence must a caller have before relying on the observation path?
Read a stable cursor from the home timeline. Check current visibility and retrieve post content. Merge high-fan-out publishers under a bounded pagination rule. No. A materialized reference does not override current visibility. Remove or tombstone the authoritative post and enforce the permitted visibility/freshness rule while cleaning projections asynchronously.
45-minute interview rubric
- 00–05: scope feed item and post and eligibility records.
- 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
- 12–28: draw post and eligibility records, numbered writes and reads.
- 28–40: challenge recovery: Choose fan-out policy under skew and preserve pagination meaning.
- 40–45: defend viewer_id placement, observations and remaining assumptions.
Go deeper
- TAO: The power of the graph - Engineering at Meta · Primary document · engineering.fb.com. Choose fan-out policy under skew and preserve pagination meaning. Verified 2026-10-26.
- RFC 9111: HTTP Caching · Primary document · www.rfc-editor.org. Choose fan-out policy under skew and preserve pagination meaning. Verified 2026-10-26.
Decision log
Choose fan-out policy under skew and preserve pagination meaning.
Preserve feed item identity and post and eligibility records ownership.
Revisit changed workload, observations or recovery objectives.