System design interview: design a news feed

A news feed system collects new posts from the people, groups and pages a user follows, ranks them and returns a page at a time, fast. The interview turns on two choices: when to build each feed (push posts into precomputed lists when they are written, or pull and merge them when the feed is read) and how to rank and paginate a list that keeps changing while the user scrolls.

By Published 8 min read

1. Clarify the requirements

"Design a news feed" usually means a social network's home screen. Confirm whether the feed is chronological or ranked, and what kinds of sources it mixes, because both change the design.

  • Functional: users create posts (text, images, links); users follow people and join groups or follow pages; the home feed shows posts from all of those sources, ranked; infinite scroll; a new post shows up in followers' feeds within seconds to a minute.
  • Non-functional: a feed page loads in a few hundred milliseconds; the feed service stays up even when ranking or a source is degraded; nobody ever sees a post they are not allowed to see.
  • Out of scope unless asked: ads in the feed, comment threads, notifications, the ranking model's training, video processing.

2. Estimate the scale

These are made-up round numbers to reason with, not any company's real traffic.

Back-of-envelope estimate for a large social feed (assumed figures)
QuantityAssumptionResult
Daily active users300 millionthe base for everything below
Feed loads5 per user per day1.5 billion a day, about 17,400 a second; about 35,000 at a 2x peak
New posts10% of users post once a day30 million posts a day, about 350 a second
Fan-out writes300 followers per poster on average9 billion feed inserts a day, about 104,000 a second
Feed list storage500 post IDs of 8 bytes per userabout 1.2 TB of IDs, before overhead and replicas
Back-of-envelope estimate for a large social feed (assumed figures). Scroll sideways on a small screen.

The numbers make the trade-off concrete. Pushing costs about 104,000 small writes a second, which a partitioned in-memory store handles. Pulling would cost, for each of 17,400 feed loads a second, a query to hundreds of followed accounts. The feed lists fit in memory across a modest cluster. So push wins for typical accounts, and the remaining question is what to do about the accounts whose posts would cost millions of writes each.

3. Define the API

POST /v1/posts
  body:    { "text": "Our team won the league", "audience": "friends", "media": ["m_12"] }
  returns: 201 { "postId": "p_4410" }

GET /v1/feed?limit=20&cursor=eyJzIjoiMTcwMjQ...
  returns: { "items": [ { "postId": "p_4410", "author": {...}, "text": ..., "likes": 52 } ],
             "nextCursor": "eyJzIjoiMTcwMjM..." }

POST /v1/feed/seen       body: { "postIds": ["p_4410", "p_4392"] }   (batched impressions)
The feed call takes a cursor and returns one, so the client never computes offsets.

4. Sketch the data model

What is stored where
DataFieldsStore and key
Postpost_id (time-sortable), author_id, audience, body, media refs, created_at, deletedSharded store keyed by post_id; author index for profile pages
Social graphfollow and membership edgesGraph or wide-column store, both directions
Feed listper user: sorted set of (post_id, score or time)In-memory store keyed by user_id, capped at a few hundred entries
Seen state(user_id, post_id) impressionsShort-lived store or a compact filter per user
Ranking featuresauthor affinity, post engagement so far, content type, ageFeature store with low-latency lookups
What is stored where. Scroll sideways on a small screen.

Time-sortable post IDs help in two places: the feed list can sort by ID when it needs chronological order, and the cursor can carry an ID instead of a timestamp that might collide. The unique ID generator walk-through shows how to make them.

5. The core decision: when to build the feed

Three ways to get posts into a feed
ApproachWrite costRead costWhere it hurts
Push (fan-out on write)One insert per follower for every postRead one precomputed listAccounts with millions of followers; work wasted on users who never come back
Pull (fan-out on read)One insert, into the author's own listQuery every followed source and mergeUsers who follow thousands of sources; slow feed loads
HybridPush for most authors, skip the push above a follower thresholdRead the list, then pull and merge from the few large sources the user followsTwo code paths to keep consistent
Three ways to get posts into a feed. Scroll sideways on a small screen.

Pick hybrid and then make it concrete. The threshold is a number you tune: the point where one post's fan-out costs more than the extra reads its followers would do. Two refinements are worth saying out loud. First, skip the push for followers who have not opened the app in weeks; if they return, rebuild their feed with a pull. Second, groups and pages with large audiences behave like large accounts and take the pull path too.

Deletes and privacy changes travel the same way as posts. A delete event removes the ID from feed lists where it was pushed, but the read path must still check the deleted flag and the audience when it hydrates, because fan-out is asynchronous and can lag. The read-time check is the real guarantee; the list cleanup is an optimization.

For the chronological variant, with a deeper look at a single very large account, see design Twitter; the same choice applied to photos appears in design Instagram.

6. The architecture

  1. Clients
    • Web and mobile apps
  2. Edge
    • Load balancer
    • API gateway
  3. Services
    • Post service
    • Feed service
    • Ranking service
    • Graph service
  4. Async
    • Post event queue
    • Fan-out workers
  5. Storage
    • Post store + cache
    • Feed lists (in memory)
    • Feature store
    • User cache
Write path (post and fan-out) and read path (candidates, ranking, hydration). A user's post goes through the API to the post service, which stores it and emits a post-created event. Fan-out workers read the author's followers from the graph service and insert the post ID into each eligible follower's feed list in an in-memory store, skipping very large authors and inactive followers. On read, the feed service takes the user's feed list, pulls recent posts from the large sources the user follows, removes seen and blocked items, asks the ranking service to score the candidates using a feature store, then hydrates the top results from the post and user caches and returns them with a cursor.
  1. Gather candidatesRead the user's feed list (a few hundred IDs) and recent posts from the large accounts, groups and pages they follow. Drop anything already seen.
  2. FilterRemove posts from blocked or muted authors and anything the user is no longer allowed to see. Do this before ranking so no work is spent on posts that cannot be shown.
  3. ScoreFetch features for each candidate in one batch and score them with the ranking model. A lightweight first-pass score can trim the list before a heavier model runs on the top part.
  4. DiversifyApply rules after scoring: no more than a couple of posts in a row from one author, a mix of content types, and a boost for very recent posts from close connections.
  5. Hydrate and returnTurn the top IDs into full posts with author names and counts from caches, return 20 of them and a cursor, and keep the rest of the ranked list briefly for the next page.

7. Scale it

  • Cache the ranked session. Ranking a few hundred candidates per scroll page is wasteful. Rank once per feed open, keep the ordered list for a few minutes keyed by session, and serve the next pages from it.
  • Batch the fan-out. Workers read the follower list in pages and write to the feed store with pipelined batch inserts, partitioned by follower so each batch hits one node.
  • Cap the lists. Keep only the newest few hundred IDs per user; older history comes from a slower pull if anyone ever scrolls that far.
  • Degrade gracefully. If ranking is slow or down, fall back to chronological order from the same candidates. A plain feed beats an error screen.
  • Partition the post and feed stores by their keys, as described in sharding, and keep hot posts in a cache in front of the post store (see caching).

Cursors on a ranked feed

Offset pagination breaks as soon as new posts arrive: page two shifts and the user sees duplicates. With a cached ranked list per session, the cursor encodes the session ID and the position in that list. When the session expires or the user pulls to refresh, a new ranking starts and the client asks for a fresh first page. The client also sends seen post IDs so the next ranking does not repeat them.

8. What breaks, and what you do about it

Failure modes worth naming
FailureEffectMitigation
Fan-out backlog after a busy eventNew posts reach followers lateAutoscale workers on queue lag; process fan-out for active users first
Feed list node lostSome feeds come back emptyReplicas; on an empty or missing list, rebuild by pulling from followed sources and write it back
Ranking service slowFeed latency rises for everyoneTimeout and fall back to chronological order from the same candidates
Post deleted after fan-outID still sits in many listsRead-time check on hydration hides it; an async job removes it from lists
Author changes a post to privateEarlier fan-out reached people who can no longer see itAudience checked at read time on every request, never trusted from the list
Failure modes worth naming. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Push, pull or hybrid. Push makes reads cheap and wastes writes on inactive users and huge audiences; pull makes writes cheap and reads slow. Hybrid adds a second path but fits real follower distributions.
  • Freshness versus cost. Re-ranking on every scroll page keeps the feed lively but multiplies ranking cost. Ranking once per session is cheaper and more stable.
  • IDs or full posts in feed lists. Storing full posts saves a lookup but copies data millions of times and makes edits and deletes painful. IDs plus caches are the usual choice.
  • Consistency. A follower seeing a post a few seconds late is fine; a blocked user seeing a post is not. Spend the strong checks on permissions and let everything else be eventually consistent (consistency and CAP has the vocabulary).

10. How to talk through it in the interview

Fictional example

Defending the hybrid threshold
Interviewer
Why not push everything? Writes are cheap.
Candidate
For a typical author with 300 followers, push is what I do. But an account with 20 million followers would turn one post into 20 million inserts, and most of those followers will not open the app before the post is stale. Above a threshold I store the post once and merge it when a follower reads their feed. The threshold is tuned from measurements, not fixed.
Interviewer
What does that do to read latency?
Candidate
Most users follow only a handful of accounts above the threshold, so it adds a few parallel lookups of recent posts, which are hot in cache anyway.

For 45 minutes, a reasonable shape: 5 minutes settling ranked versus chronological and the sources, 5 on the estimate (the fan-out writes per second are the key number), 5 on the API with the cursor and the data model, 10 on the write and read paths, about 15 on hybrid fan-out and the ranking pipeline, and 5 on failures. Leave pagination and deletes as short points unless asked.

  • Compute the fan-out write rate before choosing push.
  • Say that permissions are checked at read time, every time.
  • Have a fallback for when ranking is unavailable.

Practicing this design with Natively

Ask a friend to run a mock round and push hard on the push-versus-pull question, or play both roles yourself on a call. Natively keeps a live transcript of the session and, when the interviewer asks something, can propose points to cover; checking those against your own answer shows whether you mentioned inactive users, deletes or the ranking fallback. You can also ask it for a quick diagram of the read path to compare with what you drew. Notes and the transcript remain afterwards so you can study where your explanation of cursors got tangled.

Questions people ask

Should a news feed use fan-out on write or fan-out on read?

Use both. Push new post IDs into followers' feed lists for ordinary accounts, because reads far outnumber writes. For accounts with huge followings, store the post once and merge it when a follower reads their feed. Also skip the push for followers who have been inactive for weeks.

How does ranking fit into a news feed design?

Treat it as a pipeline on the read path: gather a few hundred candidate posts, drop posts that are blocked, already seen or no longer permitted, fetch features in a batch, score them, then apply diversity rules. Rank once per feed session and serve later pages from that ordered list.

How do you paginate a news feed?

Use an opaque cursor instead of page numbers. With a ranked feed, the cursor points into the ordered list cached for the session; with a chronological feed, it can carry the last post ID if IDs are time-sortable. Offsets break because new posts arrive at the top while the user scrolls.

What happens when a post is deleted after fan-out?

The post ID may already sit in many feed lists. An asynchronous job removes it, but the real protection is a check at read time: when the feed service hydrates posts, it hides anything deleted or no longer visible to the reader.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP