Case study V.2Intermediate

Design a News Feed Like Twitter

The central question is when to do the work: when a post is written, or when a feed is read. The answer changes with follower count, which is why every real feed is a hybrid.

The short answer

Requirements. Publish posts with text and media, follow and unfollow, and read a paginated feed of followed accounts, newest first; the feed loads in under 200 ms, a new post may take a few seconds to show up, and reads far outnumber writes.

Feed reads
35,000 per second300M daily users, 10 opens each
New posts
7,000 per second2 per user a day
Push cost
1.4M inserts per secondat 200 followers a post
Feed cache
about 1.2 TB500 post IDs per user

The design. Publishing stores the post once, then fan-out workers push its ID into the feed cache of every follower, a Redis list capped at about 500 IDs. Accounts above about 100K followers skip the fan-out, and the feed service merges their recent posts in at read time: the hybrid of push and pull that large feeds use. A read takes the IDs from the cache, fills in the posts from the post and user caches, and pages with a cursor.

Interview prompt

Design the home timeline for a social network: users follow others and see their posts, newest first.

Requirements and estimates

Functional requirements

  • Publish a post with text and media.
  • Follow and unfollow users.
  • View a paginated feed of posts from followed users.

Non-functional requirements

  • Feed loads in under 200 ms.
  • A new post may take a few seconds to appear (eventual consistency).
  • Read heavy and highly available.

Estimates

Feed reads  300M DAU × 10 opens ÷ 86,400 s     ≈ 35,000 reads/s
New posts   300M DAU × 2 posts ÷ 86,400 s      ≈ 7,000 posts/s
Fan-out     7,000 posts/s × 200 followers      ≈ 1.4M feed inserts/s if we push
Feed cache  300M users × 500 post IDs × 8 B    ≈ 1.2 TB of IDs in memory

API and data model

API

POST /v1/posts
{ "text": "...", "mediaIds": ["m_81"] }

GET /v1/feed?limit=20&cursor=1783229482342
→ 200 { "posts": [...],
        "nextCursor": "1783228190031" }

Data model

posts    post_id PK, author_id, text,
         media_ids, created_at
follows  follower_id, followee_id
feeds    user_id → [post_id, ...]
         Redis list, capped at ~500

Whiteboard

What you sketch in the first five minutes, before any of the detail below. Draw both paths, then do the push or pull arithmetic out loud.

1. Publish path and read path

Say: do the work when a post is written, so that opening the feed is one cache read.

authorpostservicepostsfan-outworkersfeed caches500 IDs eachreaderfeedservicepost + usercachesone push per follower1 IDs2 celebrityposts3 fill in postspage + cursor35,000 reads/s7,000 posts/s
  1. Publish: store the post once, then fan-out workers push its ID into every follower's feed cache.
  2. Read: take the reader's IDs from the cache and merge in the few celebrities they follow.
  3. Fill in the posts and authors from caches, and return a page with a cursor.

Next question: why a cursor and not an offset? New posts arrive at the top and shift every offset, so page two would repeat items.

2. Push, pull or hybrid

Say: the choice is where the arrows multiply: on every post, or on every feed open.

an author with 1,000 followers, a reader following 300 (5 celebrities)pushpullhybridwrites per post1,00011,000lookups per open13001 + 5a 50M celebrity50M writes11about 50 s of fan-outhybrid: push for most accounts,merge the few celebrities in at read timereads are 5 to 1 over posts, so make reads cheap
  1. Push costs one write per follower and makes a read one lookup.
  2. Pull costs one write and a lookup per account the reader follows.
  3. Hybrid pushes for ordinary accounts and pulls only celebrities, above about 100K followers.

Next question: what about users who have not opened the app in a month? Skip their fan-out too, and build their feed by pull when they come back.

Architecture: the publish path and the read path

Two paths. Publishing writes the post, then fan-out workers look up followers and push the post ID into each follower’s feed cache. Reading takes the list of IDs from the feed cache and hydrates them from the post and user caches. Feeds hold only IDs, so edits and deletions show up without rewriting feeds.

Fan-out on write or on read: push or pull

Where the arrows multiply. Push does one write per follower when a post is created, so reading is a single lookup. Pull writes once, but every feed open queries every account the reader follows and merges the results.

Calculator: what one post and one feed open cost

Push (on write)Pull (on read)Hybrid
Writes when this author posts
Lookups when a reader opens the feed
Time until every follower can see it (1M inserts/s)

Hybrid is the standard answer: push for ordinary accounts, and for accounts above a threshold (say 100K followers) skip fan-out. At read time the feed service merges the precomputed feed with fresh posts from the few celebrities the reader follows. Skip fan-out to users inactive for 30 days too, and build their feed by pull when they come back.

Feed pagination with a cursor, and ranking

Paginate with a cursor (the last post ID seen), never with OFFSET. New posts arriving at the top shift every offset, so page two by offset repeats items; a cursor stays stable. Ranked feeds fetch a few hundred candidates, score them by affinity, recency and engagement, and cache the ranked page for a few minutes.

What the interviewer probes next

A user follows someone new. When do old posts appear?

Backfill asynchronously: fetch the new followee’s recent posts and merge them into the follower’s cached feed. Unfollow is handled by filtering at read time and cleaning the cache lazily.

The feed cache node dies. Now what?

The feed cache is derived data. Rebuild a user’s feed on demand by pulling recent posts from their followees, then resume pushing. Replicate the cache so a single node loss rarely forces this.

How are deleted or edited posts handled?

Feeds store IDs only. Hydration reads the current post, and deleted posts are filtered out at read time, so nothing needs to be rewritten across millions of feeds.

How do media uploads fit in?

Clients upload directly to object storage with a pre-signed URL, a worker creates thumbnails, and the CDN serves them. Posts keep only media IDs.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy