Build a Ranked Daily Reading Feed from Thousands of Publishers
System DesignModel answerLast updated
Design a platform that pulls articles from many external publishers and serves each of millions of daily users a ranked, tailored feed in under 200ms, while staying up when sources fail.
Design a Tailored Reading Feed
Your team is building a product that collects articles from thousands of publishers, through RSS feeds and third-party news APIs, and shows each person a ranked list that reflects their interests and past behavior.
What the system must do
- Collect content. Regularly pull articles from outside publishers and convert them into one consistent format.
- Serve a tailored feed. For a given user, return an ordered list of articles.
- Learn from behavior. Capture clicks and other interactions so later feeds get better.
Targets
- Scale: 10 million daily active users; about 10,000 new articles arrive per hour.
- Speed: The feed must load in under 200ms.
- Resilience: The product must keep working when some publishers are unreachable.
What your answer should cover
- A high-level architecture and the flow of data between components
- Data models for articles, user profiles, and interaction events
- How articles are stored and indexed so retrieval is fast
- How you rank content for each user
- How you cope with traffic spikes and keep caches consistent
State your assumptions, include rough capacity numbers, and explain the trade-offs behind your main choices.
Hints
Hint 1
Do the arithmetic early: feed reads per second, article arrivals per second, and event volume. You will find that article writes are tiny, and the real difficulty is personalizing for millions of users within the latency budget.
Hint 2
Keep the write path (fetching and enriching articles) separate from the read path (serving feeds) with a message queue, so a slow or failing publisher never affects readers.
Hint 3
Do not score every article for every user. Think in two stages: a cheap step that narrows a few hundred thousand fresh articles to about a thousand candidates, then a heavier model that ranks only those.
Hint 4
Decide what to precompute versus compute on request. Precomputing feeds for all 10M users every few minutes is wasteful; consider lazy computation with caching and event-based invalidation.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
1. Clarify and size the problem
Questions worth asking: is the feed infinite scroll or roughly the top 50 items? How quickly must a new article appear (assume 5 minutes)? Is full-text search in scope (assume optional)?
| Quantity | Estimate |
|---|---|
| Feed loads | 10M DAU x ~5 loads/day = 50M/day, about 600 QPS average, ~3k peak, ~10k in breaking-news bursts |
| New articles | 10k/hour, about 3/sec, ~240k/day |
| Article storage | ~5 KB each, about 1.2 GB/day, which is small |
| Interaction events | ~20 per user per day = 200M/day, about 2.3k/sec average, ~10k/sec peak |
| Live candidate pool | Relevance decays within ~48h, so roughly 500k live articles, which fits in memory |
The takeaway: ingesting articles is easy. The hard parts are personalizing for 10M users, absorbing event throughput, and holding p99 latency.
2. API sketch
GET /v1/feed?user_id&cursor&limit=20returns articles plus a next cursor.POST /v1/eventstakes impression, click, dwell, share, and hide events. It returns202immediately and clients batch their uploads.
3. Data models
- Article (document store or Postgres, plus a search index): id (hash of canonical URL), source, url, title, summary, body, published and ingested timestamps, language, categories, entities, an embedding vector, a simhash for near-duplicate detection, a cluster id, and a popularity score.
- User profile (key-value store such as DynamoDB or Cassandra, hot entries in Redis): explicit topics, followed and blocked sources, decaying topic-affinity weights, a user embedding, locale.
- Event (Kafka, then a data lake for training; recent events in Cassandra partitioned by user and clustered by time): event id, user, article, type, dwell time, display position, timestamp, device.
- Feed cache (Redis):
feed:{user_id}holding (article_id, score) pairs with a TTL of about 15 minutes.
4. Architecture
Write path: Scheduler -> fetcher workers -> Kafka (raw) -> enrichment (parse, language, topics, entities, embedding, simhash dedup) -> Kafka (articles) -> article store, search index, vector index, candidate cache.
Read path: Client -> CDN/API gateway -> feed service -> Redis. A hit returns immediately. A miss runs candidate generation, then the ranker, then writes the result to the cache.
Feedback path: Client -> event collector -> Kafka -> stream processor (profile and popularity updates) and data lake (offline training).
Kafka isolates the halves. If publishers fail or enrichment lags, readers keep being served from the existing pool. That is the main availability argument.
5. Ingestion details
- Scheduling: a priority queue keyed by next-poll time. Frequent publishers are polled more often. Use conditional GETs (ETag, If-Modified-Since) to skip unchanged feeds.
- Fetchers: stateless, with timeouts, exponential backoff, and a per-source circuit breaker so a dead publisher is polled less and never blocks others.
- Enrichment: idempotent, keyed by the canonical-URL hash, so retries and duplicates are harmless. Simhash or embedding similarity groups near-duplicate stories into clusters.
6. Personalization: two-stage ranking
Stage 1, candidate generation (~30ms). Reduce ~500k articles to ~1,000 by merging several sources:
- ANN search (HNSW/FAISS) with the user embedding, top ~300
- Inverted-index lookups on categories and followed sources, limited to the last 48h
- Trending items globally and per locale
- New items from followed sources
Then remove already-seen articles (per-user Bloom filter) and blocked sources.
Stage 2, ranking (~50ms). A GBDT or small two-tower/DNN model predicts click probability and expected dwell time from features such as embedding similarity, topic affinity, source CTR, article age, popularity velocity, and recent session topics. Combine them with a freshness decay:
score = (w1 * P(click) + w2 * E[dwell]) * exp(-age / tau)
Diversity re-ranking. Allow one article per story cluster and about three per source, using an MMR-style pass so the feed is not ten copies of one event.
Latency budget on a miss: profile 5ms, candidates 30ms, features 20ms, inference 40ms, overhead 25ms, about 120ms total, leaving headroom under 200ms. A cache hit takes under 10ms.
Precompute vs on demand. Scoring 1,000 candidates for 10M users every few minutes is wasteful. Precompute only for recently active users, compute lazily for the rest, cache the result, and refresh on triggers.
7. Feedback loop
- Streaming: a Flink-style job updates topic affinities with exponential decay, the seen-filter, and article popularity/CTR counters. A significant affinity shift invalidates that user's cached feed.
- Batch: daily retraining of the ranker and embeddings from the data lake, validated offline (AUC, NDCG) and then through A/B tests on CTR, dwell, and retention.
- Position bias: log display position with every impression so training can correct for it.
8. Spikes and cache consistency
- Feed and model services are stateless and autoscale. Add load shedding as a safeguard.
- During breaking news, many users want the same content. Use request coalescing (single-flight) on cache misses to prevent stampedes, and add jitter to TTLs so entries do not expire together.
- Keep a global or locale-level fallback feed to serve if personalization is slow or down. Degrade gracefully: skip heavy features first, then the model, then fall back to popularity.
- Consistency is eventual by design. A 15-minute TTL plus event-driven invalidation is enough; a user briefly seeing a slightly stale feed is acceptable. Hide and block actions are the exception: apply them at read time as a filter so they take effect immediately even on a cached feed.
- Shard Redis by user id, and replicate for failover.
Trade-offs
- Precompute everything: lowest read latency but huge compute and stale results. Lazy compute with caching is cheaper.
- A heavy ranking model improves quality but eats the latency budget, so keep it on ~1,000 candidates only.
- Strong cache consistency costs latency and complexity and is not needed for a news feed.
Common mistakes
- Treating ingestion as the bottleneck when it is only ~3 articles/sec.
- Scoring the entire corpus per request.
- Coupling fetching to serving, so a failing publisher hurts readers.
- Ignoring duplicates, so one story floods the feed.
- Forgetting position bias, cold-start users (fall back to trending and explicit topics), and monitoring (freshness lag, cache hit rate, p99, per-source health).