We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design and AI Engineering, by Roni Das. 984 interactive lessons.
Start LearningSystem design interview guide
Short answer
Twitter system design centres on the home timeline. For most users, a new tweet is copied into each follower's timeline cache when it is posted (fan-out on write). For celebrities with millions of followers this is skipped, and their tweets are fetched and merged when the timeline is read. Search and trending topics run on the same tweet stream.
in this guide
7 parts open to everyone · 3 with a free account · 3 with the course
You can read 7 of 13 parts. A free account opens the deep dive; the course opens all of it.
Design Twitter forces you to confront one of the cleanest trade-offs in system design: fan-out on write vs fan-out on read. It also tests how you handle hot keys (celebrities with millions of followers), real-time ranking, and search at scale.
This page is the free part.
₹1,111 in India$25 everywhere elseonce, for the whole course
The System Design course covers the Twitter design across a run of lessons, not one page. These 4 alone are about 95 minutes of step-by-step reading, every one with a quiz.
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
This guide is built on these 6 lessons. Each one teaches one piece of the Twitter design above, step by step.
Lifetime access for ₹1,111 in India or $25 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Two courses by the author of this page:
770 lessons · 18 free to read
₹1,111 in India · $25 elsewhere, once
Get System DesignYou own this course
214 lessons · 10 free to read
₹1,333 in India · $35 elsewhere, once
Get Generative AI and Agentic AIYou own this course
Save your progress and get the interview checklist PDF
Twitter, now X, serves 500 million tweets per day to 600+ million users, with home timelines that must update in under 5 seconds.
Designing Twitter is the canonical timeline generation problem. You decide between push-based fan-out (precompute every follower's timeline) and pull-based aggregation (build on read), and the answer is almost always a hybrid that depends on follower count. It also touches search, ranking, and trending topics.
Where it shows up
Commonly asked at Meta, Google, Amazon, X (formerly Twitter), LinkedIn, Pinterest, Reddit, and TikTok. It is one of the top 3 system design interview questions for any social product.
Spec sheetTwitter
worked through below, with the maths
The hard parts of this design are taught step by step in the System Design course: Fan-Out/Fan-In, Database Sharding and Consistent Hashing.
The fan-out/fan-in pattern splits work across parallel workers and combines the results. Includes a search across shards example and a sequence view.
Splitting a database across multiple servers, the nuclear option for scaling writes, and the architecture behind Instagram, Uber, and YouTube.
The algorithm that makes adding or removing nodes cheap, an interview favorite and production essential.
How key-value databases work, how to design good keys, and how Redis, DynamoDB and etcd compare. Includes a diagram of a GET and SET operation.
all part of
System Design Masterclass
770 lessons · about 287 hours · 18 free to read
₹1,111in India, by UPI
$25everywhere else, by PayPal
You own this course
Continue with Fan-Out/Fan-Inpay once,
yours for life
Live from the course bench
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Daily active users
250M
Roughly 40% of 600M registered users active daily based on public reporting.
Tweets per day
500M
Average 2 tweets per DAU. Peak rate during major events (sports finals, elections) is ~10x.
Tweets per second (peak)
50K
500M per day with a 10x peak factor.
Average followers per user
200
Median is much lower (~30), but power users with millions of followers skew the average. Used for fan-out cost.
Timeline reads per second
300K
Reads dominate writes by ~6x. Every app open and every pull-to-refresh is a read.
When a user posts a tweet, the Tweet Service writes to a sharded SQL store partitioned by user_id and emits an event to Kafka. A Fan-Out Service consumes the event. For normal users (few followers), it precomputes by writing the tweet_id into each follower's timeline cache (Redis sorted set, key user_id, score timestamp). For celebrities (millions of followers), it skips fan-out entirely. When a user requests their home timeline, the Timeline Service reads the precomputed Redis cache for normal-follow content and separately fetches the latest tweets from any celebrities they follow, then merges and ranks before returning. Search runs through a parallel Search Service backed by Elasticsearch, which consumes the same Kafka stream and indexes tweets. Trending topics are computed by a Flink job over the tweet stream.
In a real interview, sketch this on the whiteboard before diving into any single box.
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
Owns tweet writes. Persists to sharded SQL (Manhattan in the original Twitter stack, or PostgreSQL shards). Emits a TweetCreated event to Kafka. Reads by tweet_id come from a cache fronting the SQL store.
Stores the follower and following relationships. Heavy-read service. Backed by FlockDB historically, or a custom graph store on top of sharded MySQL. Aggressively cached.
Consumes TweetCreated events. For each follower (up to a threshold like 100K), writes the tweet_id into the follower's timeline cache. For high-follower accounts (celebrities), skips fan-out and relies on the Timeline Service to pull at read time.
Per-user Redis sorted set keyed by user_id with tweet_id sorted by timestamp. Capped at the most recent 800 tweets per user. Hit rate is over 99% for active users.
Reads the user's timeline cache, layers in pulled tweets from celebrity follows, ranks (chronological by default, or by relevance), and returns to the client.
Elasticsearch or a custom search engine (Twitter's Earlybird is a custom Lucene fork). Indexes tweets within seconds of creation. Serves keyword, hashtag, and user search.
Flink or Storm job over the tweet stream, grouping by hashtag and region. Surfaces top-N trending per locale every minute.
tweets. Sharded by author_id. Snowflake IDs encode timestamp so they sort naturally. Read by tweet_id is heavily cached.
Every table for Twitter, its keys, and which store fits it and why.
Push vs pull for timeline generation. Push (fan-out on write) writes a tweet into every follower's timeline cache when the tweet is created. Reads are O(1): just read the cache. But for a celebrity with 100M…
4 deep dives on the parts that break at scale: Push vs pull for timeline generation; Handling the celebrity problem (hot keys); Real-time search with Elasticsearch or Earlybird.
Push vs pull vs hybrid for timelines. Pure push fails for celebrities. Pure pull is too slow for normal users. Hybrid (push for low-follower, pull for high-follower) gets you 99% of the speed without the…
5 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
A Redis node holding a few million timeline caches dies. What happens to those users, and how do you recover?
4 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design Twitter with the AI tutor.
Twitter (now X) historically used Manhattan, a custom multi-tenant KV store, for tweet and user data. The fan-out service was originally Rockdove, a Scala service that wrote into Redis. The search engine is Earlybird, a custom Lucene fork. The follow graph was stored in FlockDB. The recommendation timeline (For You) uses a system called Heron for stream processing and a deep learning ranking model. Many of these systems have been rewritten or replaced under X.
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
Fan-Out and Fan-In
intermediate / messaging event systems
Database Sharding
foundation / database fundamentals
Consistent Hashing
intermediate / data replication distribution
Key-Value Stores
intermediate / database types storage
Capstone: Design Twitter Feed
capstone / capstone
Data Partitioning
intermediate / data replication distribution
Cache Invalidation
foundation / caching strategies
interview readiness
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
India: UPI, cards or netbanking through Razorpay. Elsewhere: card or PayPal. Download at once from My packs.
NEWSystem Design Hands-On
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.
Free PDF · 79 pages
25 real tech interview questions, answered in full
Five from each of our AI, GenAI, Inference, Maths for ML and Forward Deployed packs. Each with a diagram and a model answer. Free by email.
It is really nice and good Please join the course