Advanced Concepts · Concept lesson
News Feeds: Fanout, Ranking, and Freshness
Balance write-time fanout and read-time assembly while keeping feed freshness, ranking, privacy, and cost measurable.
Written for readers who already know the basics. If the words here are new to you, read The request lifecycle and Capacity estimation first.
Original educational architecture · Version 2026-11-12.1 · Examples use stated hypothetical assumptions, not a company's actual design.
What you will be able to explain
- Compare push, pull, and hybrid feed construction strategies.
- Estimate fanout work, storage, and hot-key pressure from traffic assumptions.
- Design pagination, ranking refresh, and safe visibility changes.
A feed is a ranked view over changing relationships
A news feed looks like a list, but the serving system combines authored items, follow relationships, visibility rules, ranking, and pagination. The central decision is where to pay the cost of combining those inputs. Fanout-on-write adds a lightweight reference to each recipient's feed when an author publishes, making reads fast at the cost of write amplification and stale copies. Fanout-on-read finds the reader's sources and merges their recent items on demand, reducing write work but making reads more expensive and variable. A hybrid system pushes ordinary authors and pulls items from unusually large accounts at read time. There is no universal follower-count threshold; it depends on write rate, read rate, latency target, and storage costs. The feed should store IDs and ranking features where possible, not duplicate entire private posts.
A post's visibility is a correctness constraint, not just another ranking feature. If an account becomes private, a follower is removed, or a post is deleted, precomputed feed entries can become stale. The read path must re-check visibility or use a revocation mechanism whose freshness is within the accepted security contract. Cached feeds and pagination tokens must not expose data after access changes. Ranking is also distinct from eligibility: first determine which items the user may see, then score and order them. A feed that is fast but unexpectedly includes an inaccessible post is a security incident. A feed that is perfectly filtered but takes several seconds may violate the product's availability objective. Design both layers explicitly.
Build fanout around stable references and bounded work
For write-time fanout, a publish event identifies the post, author, creation time, and version. The fanout worker reads recipient IDs in pages and writes `(recipient_id, post_id, created_at)` references idempotently. A uniqueness key prevents duplicate entries after retries. Large recipient sets should be processed as durable jobs with checkpoints, not loaded into one memory array or one enormous transaction. The post remains in its authoritative store; the feed entry is a pointer that can be discarded and rebuilt. Reads batch-fetch the referenced posts, apply current visibility, and then rank the eligible candidates. Missing or deleted post records should be skipped safely and counted as stale references.
For pull-based assembly, the service queries recent items for each followed source and performs a k-way merge by time or score. As follow count grows, fan-in increases; concurrency limits and per-source timeouts avoid one slow source blocking the entire page. A hybrid can route high-fanout accounts through a separate pull set while ordinary accounts use push. Thresholds should be based on observed distribution, not a single hard-coded global number. For ranking that changes over time, store compact candidate pools and ranking features, then rerank a bounded window. Make the time and model version part of experiments so a ranking change can be rolled back and compared.
Estimate fanout and read pressure before choosing
Suppose 40,000 posts are created each day and the average author has 600 followers. Naive fanout creates 24 million feed-entry writes per day, or about 278 writes per second on average. If traffic peaks at five times average, budget around 1,390 writes per second before retries, hot accounts, and replica overhead. The average is not enough: if one creator has 8 million followers and posts 20 times a day, that creator alone asks for 160 million references daily. A pull or hybrid path for that account prevents one write from dominating the system. If each reference consumes an illustrative 80 bytes on disk before indexes and replication, 24 million references use about 1.92 GB/day raw; three replicas and index overhead can multiply that substantially. These are planning assumptions, not cloud pricing or storage quotes.
Now assume a reader opens the feed 8 times a day and follows 500 sources. Pulling 20 recent candidates per source means inspecting up to 10,000 candidates per session before deduplication and ranking. If each source query takes 10 ms but fan-out is sequential, the naive path can take seconds; bounded parallel reads and cached source windows reduce wall-clock time but increase concurrent load. A hybrid system can bring ordinary candidates from a precomputed inbox and fetch only a few high-volume sources. Measure p50 and tail latency, candidate count, dropped/filtered count, and freshness by author class. Compare total write and read work under peak, not just a single average user.
Authoritative record and versioned event.
Writes idempotent references for ordinary audiences.
Stores post IDs, not copied private content.
Read-time fetch avoids enormous write amplification.
Deduplicates and ranks a bounded set.
Applies current access before returning titles or bodies.
Uses stable cursor and explicit refresh behavior.
- Post published → Fanout worker: durable publish event
- Fanout worker → Recipient inbox: ordinary followers
- Post published → High-fanout source set: high-fanout source
- Recipient inbox → Candidate merge: precomputed IDs
- High-fanout source set → Candidate merge: bounded recent candidates
- Candidate merge → Visibility check: rank eligible candidates
- Visibility check → Reader page: authorized page
Time order, ranking, and pagination contracts
A chronological feed is simple to explain and test. Ranking can improve relevance but introduces model features, exploration, quality evaluation, and potential feedback loops. Consider using a bounded candidate window and deterministic tie-breaker such as `(score, created_at, post_id)` so pagination is stable. A cursor should carry a high-water mark or equivalent snapshot boundary; offset pagination is fragile because insertions shift later rows and large offsets are expensive. Even with a cursor, ranking updates can move items between pages. One practical contract freezes the candidate ordering for a short session window, while a refresh starts a new window. State whether users can see new items only after pulling to refresh or whether the feed inserts them continuously.
Ranking quality should be evaluated with human-labeled examples or carefully designed experiments, not click-through alone. Clicks can reward sensational content or reflect position rather than usefulness. Include diversity, freshness, hides, reports, and explicit user controls as signals. Explain how ranking features are stored and for how long. A model rollout should have a holdback, guardrail metrics, and a rollback path. A simpler recency score may beat a complex ranker when training data is sparse, feedback is biased, or the feature has no owner. Accessibility matters too: changing content order should be understandable, keyboard navigation should not jump unexpectedly, and a live announcement should not overwhelm screen-reader users.
Handle lag, deleted posts, and viral bursts
During a viral burst, a fanout queue can grow faster than workers can process it. Track oldest publish event age and per-author fanout completion, not just global queue size. Apply backpressure and prioritize active readers or recent posts rather than starting unlimited work. If a post is deleted or its visibility narrows while fanout is incomplete, a tombstone or version check must prevent late workers from restoring it. Read-time filtering is a valuable safety net, but it costs extra source lookups; cache policy decisions only within an explicitly acceptable revocation delay. When the source authorization service is down, choose a fail-closed behavior for private content.
Duplicate fanout entries should be harmless under an idempotent recipient/post key. A worker checkpoint that advances before all writes can lose recipients; one that advances after writes can repeat recipients. Stable IDs and uniqueness make the latter recoverable. For a ranking-service outage, fall back to a safe chronological order only if candidate eligibility and privacy remain enforced. Avoid falling back to an unbounded source fan-in that causes a thundering herd. Restore from durable post and relationship data, and treat inbox rows as rebuildable projections. Test bulk follow/unfollow, privacy flips, account deletion, and fanout backlog replay. A feed service needs operational tools that can inspect a single recipient's source references without exposing unrelated private content.
When not to precompute or personalize
Fanout-on-write is wasteful when posts have few readers, users rarely open feeds, or recipient relationship changes dominate item lifetime. A pull model can be simpler for a small product with low follower counts and modest freshness requirements. Conversely, a pure pull model is unsuitable when reads need very low tail latency and users follow thousands of active sources. Precomputing every possible personalization can create enormous storage and invalidation costs. A chronological stream may be preferable when explainability, fairness, and auditability are more important than engagement optimization. Do not use a ranking model to make a feed feel sophisticated if its benefit cannot be measured or its harms cannot be mitigated.
A feed is not a reliable place to enforce authorization by itself. Do not return copied content just because a recipient entry was generated while access existed. Current privacy rules may be more important than avoiding a read-time check. Do not precompute sensitive recommendations without clear purpose, retention, and user controls. Avoid using individual clicks in ways that infer highly sensitive traits unless privacy and consent requirements have been addressed. For small teams, fewer moving parts often matter more than theoretical latency wins; choosing a hybrid adds routing rules, separate lag behavior, and more failure modes.
Senior questions for feed architecture
Ask for the workload distribution: posts per author, follower counts, feed opens, candidate depth, peak-to-average ratio, and the hottest accounts. Which figures are measured, and which are assumptions? What is the feed freshness SLI, and does its denominator include all eligible posts or only average creators? How does a privacy change invalidate cached and precomputed entries? Is content fetched by reference and reauthorized at read time? What happens to pagination when a new post arrives or ranking changes mid-session? A senior answer should name a stable cursor contract and describe how the system communicates refresh behavior.
Challenge both the economics and the safety story. Estimate write amplification, index/replica storage, read fan-in, and reranking cost at peak; figures should be labeled illustrative rather than current provider prices. How are viral authors handled, and how does the system limit fanout queue growth? Can deletion and account removal propagate during an outage? Which ranking signals are risky or biased, how is a holdback run, and who can disable ranking? Include keyboard and screen-reader behavior for changing content. Finally compare a simpler chronological read query, a hybrid model, and full fanout; explain what observation would cause the team to change strategies.
Terms in plain language
- Fanout-on-write
- Precomputing recipient feed entries when a post is created.
- Fanout-on-read
- Assembling a feed from followed sources when a reader opens it.
- High-water mark
- A stable pagination boundary used to avoid shifting results as new items arrive.
References and boundaries
Primary documentation supports the mechanisms described. It does not certify these hypothetical architectures, prices or sizing assumptions. Review platform-specific behavior before implementation.
Primary AWS engineering article on asynchronous fanout; it illustrates messaging fanout, not a complete personalized feed design.
Primary data-structure documentation relevant to ordered feed candidates; it does not establish a complete feed architecture.