300 million daily users writing two tweets each produce roughly 168 GB of raw tweet text per day. A Twitter feed system design that ignores that write path will queue at the app server within minutes, because every read waits on the same overloaded database.
Twitter feed system design in one baseline plus three fixes
A twitter feed system design interview answer starts with the simplest working path, then removes bottlenecks in a fixed order. Begin with a client, a load balancer, an app server and a database that serves both reads and writes. Measure where it breaks, then add a timeline cache, a fanout queue and sharding for write capacity.
The design brief used in the walkthrough is specific enough to reason about: 300 million daily active users, timelines of posts from followed accounts ordered by time, 280-character posts and a timeline load under 200 milliseconds. The interviewer supplies the missing average of two posts per user per day. What matters is that you run the arithmetic out loud, not that you guess the exact traffic.
The baseline is called fanout on read. Each timeline request becomes a query that scans the people you follow and merges their recent posts at request time. That works at small scale and collapses at feed scale, because the same expensive read repeats on every refresh with nothing between the app server and the database.
How much data does 300 million users generate
Roughly 168 GB of raw tweet text lands per day at the stated averages, before indexes, metadata or replication overhead. The calculation is 300 million users times two posts, giving 600 million posts, times 280 bytes per post in UTF-8 where one character maps to one byte. 600 million times 280 is 168 billion bytes, or about 168 GB.
That figure covers text payload only. A production schema also stores author ID, timestamps, reply and repost references, counters and index structures, so real storage per post runs larger. Use the estimate to size write throughput and logging volume, then state the assumption that you are counting text alone.
Writes are the smaller half of the load. A user might post twice a day and refresh the feed a dozen times inside one session. Reads dominate, which is why the first optimization targets the read path and the second targets the ingestion path.
Why does the timeline cache fix the read path
A timeline cache between the app server and the database converts repeated identical reads into memory hits. Every feed refresh first checks the cache; only a miss falls through to the database, and that miss also writes the result back into the cache. This is a cache-aside pattern.
The interview answer needs four concrete decisions, not the word "cache". Say them one at a time:
- Key: a prefixed home timeline identifier followed by the user ID, returning the list of recent posts for that user.
- TTL: around five minutes, which keeps the entry fresh enough that a short session sees consistent ordering.
- Eviction: least-recently-used, so long-tail users do not displace active ones.
- Population: write to the cache both on a read miss and when a new post is fanned out.
Default hit rates in a simulator are conservative. Someone refreshing their own timeline several times inside a five-minute window produces repeated hits, so a 70% default understates real traffic. Raising the modeled hit rate to 90% and saying why out loud is the kind of reasoning an interviewer is listening for. Naming the hit rate without a justification is a weaker answer, because the number is an assumption about user behavior, not a measured constant.
What does the message queue change about writes
A message queue separates writing a post from updating every follower's cached timeline. The app server writes the post to the database and publishes an event. A pool of workers consumes those events and updates the timeline cache for the author's followers. Before this change, a new post never reached any cached timeline, so each follower's next read was a guaranteed miss until the entry expired.
The queue also gives you a standard set of components to discuss: consumer groups for parallel workers, retries on failure, backpressure when the backlog grows, and a dead-letter queue for events that repeatedly fail. Mention the dead-letter queue before the interviewer asks. It shows you expect partial failure rather than treating the happy path as the whole system.
Why replicas never fix a write ceiling
Cloning a database with another replica increases read capacity and leaves write capacity unchanged. Writes pass through a single leader or through partitions, and adding copies of those partitions does not add write slots. A simulator that shows throughput flattening while you keep adding replicas is modeling a real constraint, not a bug.
Scaling the app server horizontally with four replicas helps the read path. Scaling the database with five replicas helps reads further. Neither touches ingestion, so the queue and the sharding decision carry the write path. A clean write path looks like this:
- The app server accepts the post and publishes an event.
2. A worker consumes the event, persists the post and writes it into the relevant cached timelines.
3. Replication behind that write is an infrastructure concern, not part of the request latency budget.
Sharding by user ID with hash partitioning spreads both reads and writes across leaders. Range partitioning concentrates recent activity on one shard when timestamps drive the key, and round-robin partitioning makes later lookups harder to route. Say which strategy you chose and why the access pattern favors it.
How do you handle a celebrity post without a write storm
Skip the fanout for very large accounts and assemble their posts at read time. If a user with tens of millions of followers posts, a fanout worker would need to write into tens of millions of separate cached timelines, one per follower. That burst is the problem an interviewer is waiting for you to raise.
The usual answer splits authors into two groups. Ordinary accounts get push fanout, where workers write each new post into follower timelines. Very large accounts get pull assembly, where readers merge those accounts' recent posts into the cached timeline when they load it. A threshold, based on follower count, decides which path applies.
Raise the trade-off before you are asked. Push fanout keeps reads fast and makes writes expensive for popular accounts. Pull assembly keeps writes cheap and makes every read slightly heavier. Naming both sides, and admitting that the exact threshold is a product decision, is a stronger interview answer than presenting a single mechanism as the solution.
Related problems worth one sentence each in an interview: how pagination works once the timeline is assembled from two sources, how the cache protects itself when a popular entry expires and many requests try to rebuild it at once, and how a worker pool scales when the fanout backlog grows.
What still breaks after caching, queueing and sharding
Several failure modes remain once the main three fixes are in place, and each one earns credit when you name it. The cache stampede is the best known: a popular timeline entry expires, several requests miss at the same time, and all of them rebuild the same query. A short lock or a single-flight rebuild limits the damage.
Pagination interacts with the cache. A Cursor-based approach that reads a stable snapshot is easier to serve from a cached list than offset pagination, because new posts shift offsets underneath the reader. State which one your design uses and why.
A queue that writes to the cache means the cache can lag reality by the worker's processing time. For a timeline sorted by time, that lag is usually acceptable; for a direct-message inbox or a reply notification, it may not be. Say where the consistency boundary sits. Full consistency across 300 million daily users is not achievable at 200ms without weakening something, so choose what to weaken and defend it.
What the simulator showed about the Replit prototype
The walkthrough used a browser-based system design simulator built on Replit, the browser IDE and agent platform that builds and hosts apps, and it exposed a real gap in that tool. The first version had no sharding control, so raising database replicas eventually stopped improving throughput. That behavior matches the underlying database constraint rather than an error in the simulation.
Adding sharding support required a prompt describing the write-bottleneck problem. The agent produced a plan, a preview environment, a schema migration approval step, a security scan, a build and a deploy. The deploy step matters for the comparison: a generated change still needs a migration path and a security review before it reaches production, whatever the agent claims about its own output.
One detail deserves flagging. A failed save after the sharding change traced to a parsing issue, which the agent found through production logs. Automated changes are useful and still require someone reading the failure.
Frequently asked questions about twitter feed system design
- Is fanout on read ever the right choice? Yes, for a feed where writers have few followers and no strict latency target. Fanout on read keeps writes cheap and simplifies failure handling, and it becomes untenable once read volume and leaderboards of popular authors multiply.
- Why is a 90% cache hit rate reasonable for a home timeline? A user refreshes the feed many times inside one session, and the entry lives for about five minutes, so most of those refreshes hit the same cached list. The rate is an assumption about session behavior and should be stated as one, not presented as measured traffic.
- Do read replicas have any value in this design? They raise read throughput and give you failover copies, which matters for availability. They do not raise write throughput, so they cannot replace sharding when ingestion is the bottleneck.
- When should a celebrity post bypass the fanout queue? When the follower count makes the fanout write volume exceed what the worker pool can absorb in an acceptable window. A follower threshold, tuned against worker capacity, moves those authors to read-time assembly.
- What belongs in the notes during the interview? Assumptions, key formats, TTL values, hit-rate reasoning, sharding key and strategy, and the two competing fanout modes. Written notes let the interviewer follow your reasoning without interrupting the flow of the answer.
If you want more interview practice around these mechanisms, Crazystack Typescript is a Brazilian developer community with structured tracks, and the Bootcamp do Dev Doido run by Gustavo Dev Doido covers backend fundamentals in the same conversational format that this design walkthrough uses. Worth a look if you prefer projects and diagrams to slide decks.
Turn the walkthrough into a written article
Explaining a system design out loud is one skill; keeping the reasoning in a form other people can read, search and revisit is another. The value of this walkthrough was not the final diagram but the order of the decisions and the numbers behind them.
If you have a technical explanation, an interview walkthrough or a lesson of your own sitting inside a YouTube video, that material can become a structured article you keep and reuse. Paste the video link into YouBlog, let it transcribe the video, and generate the article from what is actually said.
Read the draft before publishing and correct anything the transcript garbled.