Twitter's Software Architecture: Timelines, Fan-Out, and the JVM Backend

Twitter's architecture has three defining parts: home timelines built ahead of time by fan-out on write into Redis, a self-built database called Manhattan for tweets and user data, and a backend of Scala and Java services. Those services replaced the original Ruby on Rails application. Fan-out on write means that when a user posts, the tweet's id is pushed into every follower's cached timeline at that moment. Reading a timeline is then a single cache lookup.

The design is shaped by one ratio. In a public talk, a Twitter engineer put reads at about 300,000 requests per second against about 6,000 tweets written per second. Twitter is a reading system, so the work is moved to write time.

From Ruby on Rails to JVM services

Twitter began as one Ruby on Rails application on MySQL. As traffic grew, the single application could not keep up, and outages were common enough that the error page, the Fail Whale, became famous.

The fix was to move the backend to the Java virtual machine. Twitter rewrote its services in Scala and Java, and built Finagle, an open-source library for writing RPC services, so that every service handled connections, retries, and timeouts the same way. Engineers reported more than a tenfold increase in requests served per machine after the move. Rails remained only at the edge for a time and was then retired from the request path.

The result is a service-oriented backend. Tweetypie serves tweet objects, Gizmoduck serves user objects, a social graph service serves follower lists, and a timeline service assembles what you see.

The timeline fan-out design, step by step

  1. A tweet arrives at the write API. It is assigned an id by Snowflake, Twitter's id generator, which encodes the time so ids sort in order.
  2. The tweet is stored. The text and metadata go to the tweet store, and any media goes to Blobstore, Twitter's object store.
  3. The fan-out service reads the follower list. It asks the social graph service for everyone who follows the author.
  4. The tweet id is inserted into each follower's home timeline. Each timeline is a list in a Redis cluster, replicated three times, and capped at 800 entries. Only the id is stored, not the tweet.
  5. A follower opens the app. The timeline service reads the id list from Redis in one call.
  6. The ids are turned into tweets. The service asks Tweetypie for the tweets and Gizmoduck for the authors, in parallel, and returns the page.

The talk gave a delivery target of five seconds from post to follower timeline, with a median of about 3.5 seconds. Accounts with millions of followers cannot meet that target by fan-out alone, so their tweets are merged in at read time instead. That mix is the answer interviewers want when they ask about celebrities.

Fan-out on write compared with fan-out on read

QuestionFan-out on write (Twitter's default)Fan-out on read
Work happensWhen the tweet is postedWhen a follower opens the timeline
Read costOne cache lookup, then hydrate the idsQuery every followed account, then merge and sort
Write costOne insert per followerOne write
SuitsMost users, who read far more than they postAccounts with millions of followers
StorageA cached list per active userLittle extra storage
FreshnessA few seconds behindImmediate

Twitter uses both. Ordinary accounts fan out on write. The highest-follower accounts are excluded from fan-out and merged in when a timeline is read. An interview answer that names this hybrid, and says where the cutoff should be, is complete.

What database does Twitter use?

Twitter's main store is Manhattan, a distributed key-value database it built after outgrowing Cassandra. Twitter has said Manhattan holds tweets, direct messages, and account data, and serves tens of millions of queries per second across its clusters. Before Manhattan, tweets lived in sharded MySQL and then in Cassandra.

DataStore
Tweets, direct messages, accountsManhattan
Home timelinesRedis cluster, ids only
Images and videoBlobstore, served through CDNs
Search indexEarlybird, a modified Lucene index held in memory
Follower graphA dedicated graph service, originally FlockDB on MySQL
Hot objectsMemcached and Redis caches in front of the services

Manhattan is multi-tenant, meaning many teams share one cluster with their own key spaces and their own consistency settings. That is why a single system can hold both tweets, which tolerate slight delay, and account data, which cannot.

The Twitter tech stack in one table

LayerTechnology
Service languagesScala and Java on the JVM, with Finagle for RPC
Original applicationRuby on Rails, now retired from serving
Id generationSnowflake
Timeline cacheRedis
Primary databaseManhattan
SearchEarlybird (Lucene-based)
Cluster managementMesos and Aurora, with Kubernetes adopted later
AnalyticsHadoop, Scalding (Scala on Hadoop), Heron for streaming

How to present Twitter in a system design interview

Start with the read-to-write ratio and say that it justifies doing work at write time. Draw the write path through fan-out into Redis, then the read path as a lookup plus hydration. Name the celebrity problem before you are asked, and explain the hybrid. Finish with storage: a timeline cache that holds ids, a durable store for tweets, and an object store for media.

For the patterns behind this design, read what design pattern Twitter uses. For the interview loop itself, read what a Twitter interview is like.

How to Prepare

TAGS
System Design Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Which course is best for a software job in 2024?
How would you handle schema drift in JSON/Protobuf/Avro?
A practical guide to handling schema drift for JSON Protobuf and Avro with step by step rules real world example pitfalls interview tips a comparison table and quick FAQs for the system design interview.
What Is the Together AI Interview Process Like? (Round by Round)
Together AI's loop: a recruiter call, fast-paced coding rounds, an applied ML systems interview, and team conversations, usually inside two to four weeks.
What is technical writing in 2024?
How to understand data encryption and security for interviews?
What is the goal of system design?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$99

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.