RELIABILITY, SECURITY & CASE STUDIES · SUBTOPIC
Case Study: Social News Feed (Twitter / Instagram)
Hybrid fan-out (push for normal users, pull for celebrities), Redis timeline caches, and cursor pagination.
IntermediatePart of System Design Case Studies
Subtopics in System Design Case Studies (8)
In plain words
Most users have a few hundred friends, so when they post, a worker drops the post ID into each follower’s fast Redis list. Mega-celebrities with 50M followers skip that push and get merged live when you open your feed.
Think of it like…
Delivering morning newspapers to subscribers’ mailboxes (push) while putting celebrity breaking news on a billboard everyone reads (pull).
Loading interactive diagram
Loading interactive exercise
Theory & how it works
Why storing only Post IDs in Redis timelines saves 95% RAM
Never duplicate full post text, avatars, and media URLs into 5,000 followers’ caches! Store only compact 8-byte post_ids in Redis (ZSET scored by timestamp), then hydrate the top 20 posts from a shared post:{id} cache in one MGET.
Key points & practical guide
Summary checklist
- Hybrid fan-out solves both read speed and celebrity write storms
- Store IDs only in timeline lists and hydrate via MGET
- Use cursor pagination (
before_post_id) instead of OFFSET
When to use it
- Home feeds, activity streams, community timelines
Watch out for
- Fanning out synchronously during the
POST /tweetrequest
Quick check
Loading quiz