Real architecture · Mid
Twitter: timelines at scale (fan-out in Redis)
Real production architecture. Key points: feed fan-out.
Short answer
Real production architecture. Key points: feed fan-out. Twitter's original timeline shows each person the recent tweets from the people they follow. A public description of the company's architecture, published by High Scalability, records the asymmetry that shapes the design: about 300 thousand requests per second were spent reading timelines and only about 6 thousand per second were writes.
01 · CONTEXT
A timeline is read far more than it is written
Twitter's original timeline shows each person the recent tweets from the people they follow. A public description of the company's architecture, published by High Scalability, records the asymmetry that shapes the design: about 300 thousand requests per second were spent reading timelines and only about 6 thousand per second were writes.
When reads dominate like this, it pays to move work from the read to the write: spend more when publishing a tweet so that opening the timeline is cheap. This case follows that trade-off, shows where it breaks (accounts with many followers), and how the real design came to combine both sides. The focus here is what Twitter did with Redis, not the generic feed problem.
02 · STARTING POINT
Assembling the timeline at read time
The most direct approach is to store nothing precomputed. When someone opens the timeline, the service queries the follower graph, fetches the recent tweets from each followed account, and sorts everything. There is no extra work when publishing, but each read turns into many queries.
The user opens the timeline. The load balancer picks a service instance, which has nothing precomputed and has to assemble the result now.
The service asks the follower graph which accounts this user follows. The more accounts, the more queries follow.
For each followed account, the service fetches the recent tweets from the tweet database. One timeline read unfolds into many reads, and the database absorbs that load every time the app is opened.
The service merges the results, sorts them by time, and responds. Response time grows with the number of followed accounts, and this cost repeats on every read.
03 · FAN-OUT ON WRITE
Delivering the tweet to the timelines at write time
The architecture description says that incoming tweets are placed in a large Redis cluster, and that the adopted solution was a fan-out-on-write approach. Instead of computing the timeline when someone reads it, the system inserts each new tweet into the followers' timelines at the moment it is published.
The author sends the tweet. The load balancer forwards the request to the tweet service, which validates and writes it.
The tweet is written first to the tweet database, which holds the full content and does not depend on any timeline.
Instead of delivering to all followers within the publisher's request, the service enqueues the delivery work. The person publishing does not wait for the queue to finish.
The delivery process queries the follower graph and inserts the tweet identifier into each follower's timeline, stored in the in-memory cache. The cost grows with the number of followers of the publisher.
When a follower opens the timeline, the read service fetches the ready-made list from the cache and fills in the tweets by identifier. Reads no longer walk the follower graph.
The same source describes that a person's main timeline lives in a Redis cluster and has at most 800 entries. The limit keeps the list small and fitting in memory: the cache holds only the recent stretch, and anything older comes from the main storage.
04 · BIG ACCOUNTS
Where fan-out on write breaks and the hybrid design
The cost of fan-out on write is proportional to the number of followers. For a huge account, a single tweet turns into a flood of inserts, and the delivery queues fall behind demand: the source states that the fan-out queues for high-value accounts are backed up all the time. The same source says Twitter was shifting from doing all the work on write to doing more work on read for those accounts, and gives the example of not fanning out a heavily followed account and merging its tweets at read time.
With pure fan-out, a huge account's tweet generates a giant task. The delivery queue fills up and that account's tweets take a long time to appear, while the tweets of small accounts waiting behind it are delayed too.
In the hybrid design, the delivery process keeps spreading the tweets of regular accounts but does not spread those of heavily followed accounts. The work per tweet stays bounded.
The tweets of these accounts live in a cache of their own, read by many users. Since there are few of them and they are read a lot, this cache has a high hit rate.
When the timeline is opened, the read service takes the ready-made list from the timeline cache and merges in the tweets of the big accounts the person follows, fetched from the dedicated cache, sorting the result.
The price is a bit more work on read, which used to be just a lookup. In exchange, writes from big accounts stop being a bottleneck for the rest of the system.
A systems-interview source describes the same principle in general terms: the hybrid approach lets you choose between fan-out on read and fan-out on write for each account. The decision stops being system-wide and becomes per account.
| Criterion | Fan-out on read | Fan-out on write | Hybrid |
|---|---|---|---|
| When the work happens | When opening the timeline | When publishing the tweet | On write for regular accounts and on read for heavily followed accounts |
| Weak point | Slow, heavy read on the database | An account with many followers overloads delivery | More pieces and more rules to operate |
| When it fits | Few reads or few followed accounts | Read-dominant with a moderate number of followers | A mix of regular accounts and giant accounts |
05 · LESSONS
What to take into the interview
Three ideas come out of the case. First, the read-to-write ratio decides where to pay the cost: if reads dominate, precomputing pays off. Second, the cost of a write grows with the number of followers, so the average hides the tail of giant accounts. Third, the solution is rarely a pure model: the real design mixes both and chooses per account.
Frequently asked questions
What is Twitter: timelines at scale (fan-out in Redis)?
Real production architecture. Key points: feed fan-out.
What does the Twitter: timelines at scale (fan-out in Redis) design cover?
It is organized in these sections: A timeline is read far more than it is written, Assembling the timeline at read time, Delivering the tweet to the timelines at write time, Where fan-out on write breaks and the hybrid design, and What to take into the interview.
How long is Twitter: timelines at scale (fan-out in Redis) and what level is it?
It takes about 15 minutes to read and is rated Mid level.
Now design it yourself
Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.