DEV Community

Cover image for Design Twitter (X): the timeline system design interview walkthrough
Gowtham Potureddi
Gowtham Potureddi

Posted on

Design Twitter (X): the timeline system design interview walkthrough

Design Twitter (X): the timeline system design interview walkthrough

The request to design Twitter looks small — let a user post a short tweet and see a timeline of tweets from the people they follow — and that one line hides one of the hardest read-scale problems in system design. Doing it for a few thousand users is a database query ordered by time; doing it for hundreds of millions of users, where some accounts have 100M+ followers and the home timeline has to load in under a second, is a fanout problem with a brutal edge case and two more systems hiding behind it: search and trending. This is one of the canonical Twitter system design prompts because it forces the tradeoff every large read-heavy system eventually hits — pay the cost when a tweet is written, or every time a timeline is read.

The round turns on three decisions. First, the shape of the write path: a timeline is read far more than it is written, so you lean toward precomputing timelines — but precomputing means fanning every tweet out to every follower, and that is where the design falls apart for mega-accounts. Second, the read path that makes the sub-second home timeline real. Third, the systems a tweet feeds beyond the timeline — search and trending topics, both built on an inverted index and rolling counts. This walkthrough follows the path a strong candidate draws in a system design interview — requirements, estimate, API and data model, high-level design, then the deep dives — and at each step it names the follow-up the interviewer uses to tell a memorised answer from an engineer who understands the tradeoff.

Title card for a system design interview walkthrough on designing Twitter, showing a tweet fanning out into follower timelines with a push and pull split, beside a trending panel, on a dark citrus-and-lavender background.

How the Twitter round is actually run

A timeline design round runs about 60 minutes on a shared canvas — you draw the boxes and arrows while you talk, and the interviewer interrupts. It is a favourite because the one-line problem opens onto deep water fast: the moment you say "I'll precompute each home timeline," the question becomes what about the account with a hundred million followers, and every answer after that (the celebrity problem, the hybrid, the cache, trending) compounds. Get the fanout spine clean and you have shown the whole loop in one problem.

The interviewer rarely lets "precompute every timeline" stand. "An account with a hundred million followers tweets — walk me through exactly what happens when they hit send." That question — the write storm a naive fanout-on-write creates — is the one a copied answer can never rehearse, and the one this round is really testing.

The rounds here are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: a blank canvas, a clock, and a follow-up after every decision you make.

The five-step framework for any HLD round

Every high-level design answer fits the same spine. Say it out loud at the start so the interviewer knows you have a plan, then walk it:

  1. Clarify requirements — functional and non-functional, and what you are explicitly not building.
  2. Estimate — users, tweets, reads, and the follower distribution, to justify every later choice.
  3. High-level design — the boxes and arrows: client, timeline API, timeline service, fanout service, stores.
  4. Deep dive — the two or three decisions that actually decide this system.
  5. Follow-ups — bottlenecks, failure modes, and what you would change at ten times the scale.

What the debrief measures

The score is not "right or wrong design." A good HLD debrief reads on four dimensions, and every move below maps to one: problem solving (did you reach a fanout design and then recognise the celebrity problem it creates), communication (did you say why push beats pull for most users in a sentence), technical execution (precomputed timeline cache, hybrid fanout, cursor pagination, an inverted index for search), and time management (did you spend your 60 minutes on fanout and the celebrity case, not on the tweet schema). Reading a walkthrough teaches the design; it does not teach you to deliver it on the clock while someone pushes back.

Step 1 — Requirements: what Twitter must do

Spend the first few minutes here. Jumping to boxes before you have scoped the problem is the fastest way to design the wrong system.

Type Requirement
Functional Post a tweet; follow accounts; generate a user's home timeline of tweets from the accounts they follow, newest first; view a user's profile timeline; search tweets; see trending topics.
Functional (optional) Likes, retweets, replies, media, notifications, DMs — call these out, then scope most of them for later.
Non-functional Very low home-timeline latency (loads in under a second); read-heavy (far more timeline reads than tweets); highly available; eventual consistency is acceptable — a new tweet can appear in a follower's timeline a little late.

The sentence that earns points: "The timeline is read far more than it is written, and eventual consistency is fine, so the whole design is about moving work off the read path — which means precomputing timelines, and then handling the accounts where precomputing explodes — while search and trending are separate read-optimised systems fed off the same tweet stream." Say that and you have framed the entire design before drawing a box.

Step 2 — Capacity estimation (back of the envelope)

Estimation here proves one thing: the hard axis is the follower distribution, not raw volume.

Quantity Assumption Result
Daily active users ~250M —
Tweets ~1 per active user per day ~hundreds of millions of tweets/day
Timeline reads many refreshes/user/day read:write heavily skewed toward reads
Followers per account most have a few hundred a normal tweet fans out to hundreds
Followers per mega-account some have 10M–100M+ a single tweet fans out to tens of millions

The conclusion to say out loud: the cost is not the average tweet — it is the shape of the follower graph. Most accounts are cheap to fan out, so for them you precompute. A handful of mega-accounts are catastrophic to fan out on write — one tweet would mean 100M writes — so they must be handled differently. The whole design lives or dies on the cost of fanning a tweet out to followers versus the cost of assembling a timeline at read time, dominated by that handful of huge accounts. You have now pointed the interview at the real deep dive — fanout — before anyone asked.

Step 3 — API and data model

The API is small. A write path to post a tweet, and a read path to fetch a page of the timeline:

Endpoint Operation
POST /tweet Post a tweet — postTweet(user_id, text, media?) returns a tweet_id.
GET /timeline/home Fetch a page of the home timeline — getHomeTimeline(user_id, cursor, limit) returns tweet ids + a next cursor.
GET /search Search tweets — search(query, cursor) returns matching tweet ids.
POST /follow / DELETE /follow Follow or unfollow an account — mutates the follow graph.

The data model splits across stores. The tweet object lives once; the per-user home timeline is a list of tweet ids; the follow graph answers "who follows whom":

Entity Notes
tweet tweet_id (time-sortable, e.g. Snowflake), author_id, text, media_ref?, created_at. Stored once in the tweet store.
timeline user_id → ordered list of tweet_id (the precomputed home-timeline cache; ids, not full tweets).
follow follower_id → followee_id, plus the reverse index followee_id → followers, for fanout.

Step 4 — High-level design: the timeline architecture

Now the boxes. The design splits cleanly into a read path that must be fast and a write path that does the expensive work asynchronously:

  • Client → timeline API: the entry point for both reads and writes.
  • Timeline service (read path): on GET /timeline/home, reads the user's precomputed timeline from the timeline cache, hydrates the tweet ids into full tweets from the tweet store, and returns a page by cursor.
  • Tweet service + tweet store (write path): on POST /tweet, persists the tweet once, then hands off to fanout and to the search/trending pipeline.
  • Fanout service (write path): asynchronously writes the new tweet_id into the timeline cache of each follower — for normal accounts. This is the expensive step, done off the request.
  • Graph / follow service: owns the follow relationships and answers "who follows this author?" for fanout.
  • Search + trending pipeline: consumes the tweet stream to update an inverted index (for search) and rolling counters (for trending topics).
  • Timeline cache (Redis): a list of tweet ids per user; the reason the read path is fast.

Say explicitly that the read path never joins across the follow graph at request time — the timeline is already assembled in the cache before the user asks. That single observation is what sets up the fanout deep dive, and naming it unprompted is a signal the interviewer is listening for.

A Twitter architecture diagram showing the read path where a client calls the timeline API and timeline service reads a precomputed timeline cache in Redis then hydrates tweets, alongside the write path where the tweet service persists a tweet and a fanout service writes the tweet id into each follower's timeline cache, with a graph service supplying the follower list and a search and trending pipeline consuming the tweet stream.

Deep dive: fanout and the celebrity problem — the hybrid timeline

This is the decision that actually decides the round, and the one Twitter is most famous for. When do you do the work of assembling a timeline — when the tweet is written, or when the timeline is read?

Model How it works The catch
Fanout-on-write (push) When you tweet, write the tweet id into every follower's precomputed timeline cache immediately. Reads are instant (just read your cache), but writes are expensive — one tweet means one write per follower, which explodes for accounts with millions of followers.
Fanout-on-read (pull) At read time, fetch recent tweets from everyone the user follows and merge them into a timeline on the fly. Writes are cheap (store the tweet once), but reads are expensive — assembling a timeline means a scatter-gather across everyone you follow on every refresh.

Pick push as the default and say why in one line: the timeline is read far more than it is written and must load fast, so you pay the cost once at write time and keep the read path to a single cache lookup.

So where does push break? Exactly where a tweet has a huge number of followers. Fanning one tweet out to 100M timeline caches on write is a write storm — it saturates the fanout workers, delays every other user's tweet, and writes to tens of millions of timelines that may never be read. That is the celebrity problem, and the fix is the hybrid timeline: for the vast majority of accounts you push; for the handful of mega-accounts you don't fan out on write at all — their tweets are pulled at read time. When a user requests their home timeline, the timeline service reads their precomputed (pushed) timeline and fetches the recent tweets of the few celebrities they follow, then merges the two by time. You pay the write cost only where it is small and the read cost only where it is unavoidable, and the merge stays fast because a user follows only a handful of celebrities.

"An account with a hundred million followers tweets — walk me through what happens." You do not fan that out on write. The tweet is stored once; it is not written into 100M timelines. Every follower pulls that author's recent tweets at read time and merges them into their pushed timeline. Pushing it would be a write storm; the hybrid pulls it.

A diagram of Twitter's hybrid timeline showing normal accounts pushed into follower timeline caches on write while a mega-account's tweet is stored once and pulled at read time, then merged by recency with the precomputed timeline when a follower requests their home timeline.

System Design
HLD · Timeline / Social Feed · 60 min
Design Twitter's timeline out loud, with follow-ups

Practise on Zynter →

Deep dive: the read path — timeline cache and cursor pagination

This is the decision that makes the under-a-second home timeline real. The read path has to touch almost nothing on disk.

The timeline cache. Each user's home timeline is a list of tweet ids held in Redis — not the full tweets, just the ids in time order. Fanout-on-write pushes ids into these lists; a read is a single cache lookup for one page. The full tweet objects live once in a separate tweet store (partitioned by tweet_id), and the timeline service hydrates the page of ids into tweets only for the slice being returned. Storing ids, not copies of the tweet, keeps the fanout write cheap and the cache small.

Pagination. The timeline is paginated by cursor, not page number — the client sends the last tweet id it saw and gets the next slice, which is stable under infinite scroll even as new tweets arrive at the top. Because tweet_id is time-sortable, the merge with pulled celebrity tweets is a simple ordered merge on the id. Hot timelines stay resident in cache; cold ones can be evicted and lazily recomputed on next read.

"The home timeline must load in 200 ms — where does that speed come from?" From the precomputed timeline cache: the read path is a single Redis lookup for a page of ids, not a join across the follow graph at request time. The expensive assembly already happened asynchronously at write time, so the read only hydrates and merges a bounded page.

Deep dive: search and trending topics

This is the deep dive that separates Twitter from a plain news feed, and the one candidates forget to plan for. A tweet does not only go into timelines — it feeds two read-optimised systems.

Search: an inverted index. Tweet search cannot scan the tweet store. Instead, the search pipeline consumes the tweet stream and maintains an inverted index — a map from each term to the list of tweet ids containing it — sharded across search nodes. A query tokenises, looks up the posting lists for its terms, intersects or unions them, ranks by recency and engagement, and returns a page. The index is updated asynchronously off the tweet stream, so search is eventually consistent, which is fine.

Trending: rolling counts. Trending topics are the most-used hashtags and phrases in a recent window. The trending pipeline consumes the same tweet stream and keeps rolling counters per term over sliding time windows (often with an approximate counter like count-min sketch at the top of the funnel to bound memory), then periodically ranks the top terms per region. It is a streaming aggregation, not a query over stored tweets.

Say the unifying idea out loud: the tweet store is the source of truth, and timelines, search, and trending are each separate, asynchronously-updated, read-optimised views of the same tweet stream. That sentence is the senior framing of the whole system.

"How does search find a tweet among billions in milliseconds?" An inverted index built off the tweet stream maps terms to tweet ids, sharded across nodes; a query hits posting lists for its terms and ranks a bounded result — it never scans the tweet store.

A diagram showing a tweet stream feeding two read-optimised views, an inverted index that maps terms to tweet ids for search, and rolling windowed counters that rank the top hashtags for trending topics, both updated asynchronously off the same stream while the tweet store stays the source of truth.

System Design
HLD · Search & trending · 60 min
Explain search and trending off the tweet stream, out loud

Practise on Zynter →

The follow-ups that decide the Twitter round

Scan the probes from each deep dive and they rhyme. Master these five and you are ready for a version of the question that is not drawn exactly like this one.

  • "Push or pull — which do you pick and why?" → Push by default because the timeline is read-heavy and latency-sensitive; pull only for the mega-accounts where push is a write storm. (communication)
  • "An account with a hundred million followers tweets — trace it." → Don't fan out on write; store the tweet once and let followers pull and merge it at read time. (problem solving)
  • "How does the home timeline load under a second?" → A precomputed timeline cache in Redis read as one lookup per page; no graph join at request time. (technical execution)
  • "How does search work at this scale?" → An inverted index built asynchronously off the tweet stream, sharded; a query hits posting lists, never the tweet store. (technical execution)
  • "How are trending topics computed?" → Rolling windowed counters over the tweet stream, ranked per region — a streaming aggregation, not a query. (problem solving)

Each maps to a debrief dimension. Reading this list teaches you the answers; it does not teach you to deliver them while someone interrupts — that only comes from saying them out loud.

How to prepare: a one-week plan

You do not need fifty systems. You need this one cold and the framework automatic, so the next "design X" is just new nouns in the same five steps.

  • Days 1–2: Learn the five-step framework until it is reflex. Do Twitter end to end on paper — requirements, estimate, API, data model, the fanout boxes with a read path and a write path.
  • Days 3–4: Drill the fanout deep dive: fanout-on-write versus fanout-on-read, why push is the default, where push breaks, and the hybrid timeline. Say each tradeoff in one sentence.
  • Days 5–6: Own the read path and the two side systems — timeline cache, cursor pagination, the inverted index for search, rolling counters for trending. Answer each of the five follow-ups out loud.
  • Day 7: A full timed 60-minute round, narrating the whole way, with someone (or something) interrupting. This is the rep that counts.

This post is the deep walkthrough behind one row of the broader Top 25 system design interview questions — once Twitter is automatic, the same spine carries the rest of the list.

Frequently asked questions

How do I design Twitter step by step?

Follow the five-step HLD framework. Clarify requirements (post a tweet, follow accounts, generate a home timeline newest-first, search, trending; read-heavy; eventual consistency is fine); estimate to show the hard axis is the follower distribution, not raw volume; define POST /tweet and GET /timeline/home with a thin tweet, timeline, and follow model; draw the fanout design (a fast read path over a precomputed timeline cache and an asynchronous write path through a fanout service); then deep-dive the decisions that matter — fanout-on-write versus fanout-on-read, the celebrity problem and the hybrid timeline, the timeline cache read path, and search and trending off the tweet stream. Finish on the follow-ups about latency and scale.

What is the celebrity problem in Twitter's design?

It is the failure case of pure fanout-on-write. When an account has tens or hundreds of millions of followers, pushing a single tweet into every follower's timeline cache means tens of millions of writes, which saturates the fanout workers and delays everyone else's tweets. The fix is not to fan those accounts out on write at all — their followers pull the tweets at read time instead. Recognising this case and naming the write storm is what the interviewer is listening for.

How does the hybrid timeline work?

The hybrid timeline decides push or pull per account. For the vast majority of accounts, which have a normal number of followers, you push — fanout-on-write precomputes their followers' timelines, so reads stay instant. For the handful of mega-accounts, you pull — their tweets are stored once and fetched at read time. When a user requests their home timeline, the timeline service reads their precomputed (pushed) timeline and merges in the recent tweets of the few celebrities they follow, ordered by the time-sortable tweet id. You pay the write cost only where it is small and the read cost only where it is unavoidable.

How does Twitter search work in a system design interview?

Tweet search is built on an inverted index, not a scan of the tweet store. A search pipeline consumes the tweet stream and maintains a map from each term to the list of tweet ids that contain it, sharded across search nodes. A query tokenises, looks up the posting lists for its terms, intersects or unions them, ranks by recency and engagement, and returns a page. The index is updated asynchronously off the stream, so search is eventually consistent — acceptable for this use case and essential for the write throughput.

How are trending topics computed?

Trending topics are a streaming aggregation over the tweet stream, not a query over stored tweets. The trending pipeline keeps rolling counters per term over sliding time windows — often with an approximate counter such as a count-min sketch to bound memory at the top of the funnel — and periodically ranks the top terms per region. Because it runs off the same asynchronous tweet stream that feeds timelines and search, the tweet store stays the single source of truth and each view is updated independently.

How do I practise a system design interview out loud?

Reading a walkthrough is not the same as defending a design while someone interrupts. On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a shared design on the canvas, and a voice interviewer pushes with the follow-ups above one at a time, then gives you a debrief on problem solving, communication, technical execution, and time management. The score is a practice signal, not a hiring decision.

Practise it on Zynter

You can read every tradeoff. The round is won on the celebrity problem and search.

Pick the timeline round, draw the fanout design on the canvas, and defend it out loud to a voice interviewer that keeps asking "push or pull?" and "what about the account with a hundred million followers?" — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).

Practise the timeline round →
Browse all interview tracks

Top comments (0)