SteelReed

Search

Search posts, questions…

7. System Design

Designing a Threads-style news feed: push, pull, hybrid and celebrities

A microblogging case study for 500 million users: requirements, estimates with the arithmetic (and the wrong numbers you often see), API, data model on ScyllaDB, fan-out on write versus on read, the hybrid model for celebrities, tracking active users, reaction counters, trending posts, and how to present it in 45 minutes.

18 Nov 20268 min readSenior

–

The news feed is a classic system design question because it forces you to choose between expensive writes and expensive reads. This post walks through a full interview for a Threads-like social network; the full 45-minute presentation framework is in the URL shortener post.

1. The problem

Version one: the feed is a SQL query JOIN follows ... ORDER BY created_at DESC LIMIT 20. For a user following 500 people over a posts table of billions of rows, it never gets under 100 ms, and 30K reads per second at peak brings the DB down.

2. Key idea

Push is a mail carrier dropping letters into every mailbox; pull is walking to each newspaper office yourself. Hybrid: local papers go into mailboxes, the big papers everyone reads sit at the kiosk on the corner.

Push Pull
Reading the feed very fast, one inbox read slow: N outbox reads, then merge
Posting expensive: write into every follower's inbox cheap: one write
Celebrity with 100M followers 100M writes per post no problem
Inactive users wasted copies costs nothing

2.1 How does hybrid work?

Step Write path (feed builder) Read path (feed service)
1 store the post, publish post-created read 200 inbox ids from Redis
2 regular author or celebrity (> 100K followers)? read recent posts of followed celebrities
3 regular: followers in pages of 1,000, keep active ones, ZADD to inboxes k-way merge, take 20 ids after the cursor
4 celebrity: no fan-out hydrate with MGET, drop deleted posts

The 100 ms budget: inbox ~2 ms, celebrity posts ~5 ms, parallel hydration ~10 ms. The celebrity threshold is config: choose it so one post's fan-out finishes within 5 seconds.

2.2 What makes it cheaper

  • Push only to active users: with 20% of followers active, fan-out drops 5× (116K → 23K writes/s). A user returning after 7 days gets their feed built by pull once.
  • Cursors, not offsets: new posts inserted at the top shift offset and repeat items.
  • Likes don't hit one row: UPDATE posts SET likes = likes + 1 on a viral post is lock contention. Batch through Kafka and HINCRBY once per second.

3. In Java

JAVA
List<Long> feed(long userId, long cursor, int limit) {
    List<Long> inbox = redis.zrevrangeByScore("feed:" + userId, cursor - 1, 0, 200); // push
    List<List<Long>> sources = new ArrayList<>(List.of(inbox));
    for (long celeb : follows.celebritiesOf(userId))                                 // pull, usually a few dozen
        sources.add(recentPosts.of(celeb, cursor));
    return kWayMerge(sources, limit);              // post_id is a Snowflake: bigger means newer
}
 
void onPostCreated(Post p) {                       // feed builder, idempotent
    if (followerCount(p.authorId()) > CELEBRITY_THRESHOLD) return;
    for (List<Long> page : followers.pagesOf(p.authorId(), 1_000))
        for (long f : activeOnly(page))
            redis.zadd("feed:" + f, p.id(), p.id());   // repeated ZADD creates no duplicates
}
// an author with 50K followers -> 50 subtasks on fanout-tasks; Kafka redelivers if a worker dies
Detailed estimates
Quantity Calculation Result
Posts 5 × 10⁷ / 86,400 ~580/s, peak ×3 ≈ 1.7K
Feed reads 50M × 10 per day ~5.8K/s, peak ×5 ≈ 30K
Full push fan-out 5 × 10⁷ × 200 followers 10¹⁰/day ≈ 116K writes/s
7-day post cache 3 KB × 5 × 10⁷ × 7 ~1 TB
Feed cache 200 ids × 8 bytes × 50M DAU ~80 GB

The commonly quoted "1 QPS normally, 5M QPS at peak" is wrong at both ends: derive from DAU and multiply by a peak factor of 3–5. Interviewers grade the reasoning, not the exact number.

4. Working with AI

Give the AI: the estimation table, the CQL schema (posts, user_posts, feed, followers), a diagram of the write and read paths.

Check in the AI's design:

  • Celebrities are handled; not pure push.
  • Feeds store only ids; pagination uses cursors.
  • Fan-out is idempotent on (user_id, post_id).
  • Inboxes are size- or TTL-bounded; celebrity followers are bucketed.
  • Like counters don't write to one hot row or key.

5. Exercises

Exercise 1: Choosing a model

The AI concludes "pick pull: it scales easily and writes are cheap". The average user follows 500 people and the feed target is under 100 ms. How do you push back?

Solution to Exercise 1

Pure pull means 500 outbox reads plus a merge per feed open; at 30K opens/s that's 15M reads per second, and 100 ms is out of reach. Pure push breaks on celebrities (100M writes per post). Choose hybrid: push for authors under the threshold, pull for the few dozen celebrities each user follows, push only to active users. What would change the choice: a small app where users follow few people, where pure pull is enough and simpler.

Exercise 2: A viral post

A post receives 50K likes/s. The counter is UPDATE posts SET likes = likes + 1. The like API's p99 is 4 seconds and the DB shows thousands of lock waits. Diagnose and fix.

Solution to Exercise 2

Every like writes the same row: lock contention. Fix: write reactions (post_id, user_id) so likes aren't double-counted and publish an event to Kafka; a counter service batches for 1 second and runs HINCRBY post:counters:{id} likes 50000 once. If the Redis key is still hot, split into likes:{id}:{0..15} and sum on read. Copy to the DB periodically; a few seconds of lag in the displayed number is fine.

Summary

  • The expensive part is fan-out, not posting.
  • Push reads fast and writes slow, pull the reverse; choose hybrid.
  • Push only to active users; returning users get one pull rebuild.
  • Feeds store ids, hydrate on read, paginate by cursor.
  • Batch counters; never write one hot row.

Read more: Designing a chat system.

Practice interview questions on this topic

All System Design questions →

Loading comments…
Next on the roadmapDesigning a Discord-style chat system: WebSocket gateways, message storage and fan-out for huge servers