# Twitter to the JVM: Replacing Rails Under Load | gen2.dev

> Twitter moved from one Ruby on Rails application to JVM services between 2009 and 2012 while the product kept running. How it was done, and the results.

Source: https://gen2.dev/cases/twitter-jvm/

---

Case file 8

# Twitter to the JVM: replacing Rails under load

Twitter outgrew its Ruby on Rails application in public. It replaced it one piece at a time, with services written in Scala and Java, and never scheduled a day when the old system was switched off.

![Slide: one Rails app with four pieces moved out to services on the JVM: queue 2009, tweet storage 2010, search 2011, mobile 2012. The product stayed up.](https://gen2.dev/img/case-twitter-jvm.png)

This is the case to read after a failed rewrite story. The system was just as overloaded and the pressure was just as public. The difference is that nobody at Twitter ever got to stop the old system to build the new one, so nobody tried.

## Gen 1

Twitter began as a Ruby on Rails application. Looking back at 2010, the company described it as "one of the world's largest Ruby on Rails installations." It was a single codebase worked on by the whole engineering team. Twitter's engineers called it Monorail, and the name appears on the company's own architecture diagrams.

It had two hard limits. Tweets were stored in MySQL with a single master, which struggled to keep up with writes. And the front end was inefficient: by Twitter's own numbers, its Rails servers handled only "200 - 300 requests / sec / host." Growth was being met by adding machines.

The first cracks were handled early and without ceremony. In an interview published in April 2009, three Twitter engineers explained that they had replaced the Ruby message queue that sat between the Rails front ends and the back-end workers with one written in Scala. The old queue worked in a steady state, but as one of them put it, "Sometimes our peak loads would knock it out." That was one component, moved to the JVM, with the product running on top of it.

## The decision

The 2010 World Cup forced the larger question. Twitter was at the center of a live global event, and the traffic spikes caused repeated short outages. Peaks of 2,000 tweets per second were enough to cause major stability problems.

When it was over, the engineering team set three goals: large gains in performance, efficiency and reliability; cleaner boundaries between parts of the system; and, in their words, "Most importantly, we wanted to launch features faster." They estimated that rewriting the code to run on the JVM could produce more than a tenfold performance improvement on the same hardware.

So the answer was a rewrite. What matters is the shape of it. There was no Twitter 2.0 built beside the old one. The monolith was to be taken apart into services, each one moved when it was ready.

It is worth noticing that speed was not the whole argument. Evan Weaver, a Twitter engineer, said in 2011: "The primary driver is honestly encapsulation, so we can iterate faster as a company."

## What happened

The pieces moved in order of pain.

-   **2010: storage and queues.** The back-end message queue and the tweet storage engine were rewritten in Scala. The single MySQL master gave way to many sharded MySQL databases behind a framework called Gizzard.
-   **2011: search.** The Ruby on Rails search front end was replaced by a Java server called Blender. After the launch, 95th percentile latency dropped from 800ms to 250ms, and CPU load on the front-end servers was cut in half.
-   **2012: mobile traffic.** Requests from mobile clients were routed to the JVM stack, bypassing Ruby entirely. Twitter's VP of infrastructure operations engineering described it as part of an "ongoing migration away from Ruby."

The logic inside Monorail was split into services built around what Twitter called its core nouns: a tweet service, a user service and a timeline service. A 2013 account of the architecture gives two of their internal names: "Gizmoduck is the user service and Tweetypie is the tweet object service." Even generating a tweet's ID number became a service of its own. Snowflake, first released in 2010, is described in its own documentation as "a network service for generating unique ID numbers at high scale with some simple guarantees."

Alongside the moves, Twitter built the shared parts every service needed: Finagle, a library for asynchronous network calls, and Decider, a switch system that let a team deploy code in an off state and turn it on gradually, for a percentage of traffic at a time.

The results were measured in public events. On US election night in 2008 the peak was 229 tweets per second. On election day in 2012 it was 15,107, and the failure page users knew as the Fail Whale did not appear. In August 2013 a one-second peak of 143,199 tweets per second passed without users noticing.

The new services handled "10 - 20K requests / sec / host." Twitter reported that the number of machines serving the site had dropped by between 5x and 12x.

## What made it work

-   **Stopping was never an option.** Twitter could not go quiet for a year, so the plan never included a freeze. That constraint did most of the work a [strangler fig](https://gen2.dev/guide/strangler-fig/) plan asks for.
-   **The first moves were small and at the edge.** A message queue is a component with a narrow interface. Replacing it proved the JVM in production before anything central depended on it.
-   **Order followed pain.** Storage, then search, then the main request path. Each step paid for itself in capacity or latency, which kept the work funded.
-   **Release was separated from deployment.** With Decider, new code could be live, dark and reversible. That is the opposite of a one-day [cutover](https://gen2.dev/guide/cutover/).
-   **The boundaries followed teams.** Each service had an owning team and an agreed interface, so the new system removed the organizational bottleneck as well as the technical one.

## The verdict

It worked, and it should not be mistaken for a tidy project. It took about four years. Twitter's own account says not everything it tried worked or met those goals. And Gen 1 lingered: a July 2013 summary of a talk by Raffi Krikorian, the Twitter engineering VP who wrote the 2013 account, noted that part of the write path was still running on Ruby.

That lingering is the point. Nothing depended on the last Ruby process being gone.

## What to take from it

-   **A system under load cannot be replaced all at once. Use that.** The constraint that feels like the obstacle is what makes the migration safe.
-   **Start with a component that has a narrow interface and a real problem.** The first win buys permission for the next.
-   **Build the switch before the replacement.** Being able to turn new code on for one percent of traffic is worth more than any test plan.
-   **Do not wait for Gen 1 to be gone to call it done.** Budget for [running two systems](https://gen2.dev/guide/running-two-systems/) for years, and measure the migration by the load that has moved.

## Sources

1.  [Twitter Engineering - New Tweets per second record, and how! (August 2013, reader copy)](https://blog.x.com/engineering/en_us/a/2013/new-tweets-per-second-record-and-how) - the 2010 World Cup, the goals of the re-architecture, per-host request figures, storage, Decider and results
2.  [InfoQ - Scaling Twitter to New Peaks (August 26, 2013)](https://www.infoq.com/news/2013/08/scaling-twitter/) - summary of the same post, naming Raffi Krikorian as its author
3.  [InfoQ - Twitter Shifting More Code to JVM, Citing Performance and Encapsulation As Primary Drivers (July 4, 2011)](https://www.infoq.com/articles/twitter-java-use) - interview with Evan Weaver; the Blender search front end and its latency figures
4.  [InfoQ - report on Twitter moving from Ruby to Java (Charles Humble, November 9, 2012)](https://www.infoq.com/news/2012/11/twitter-ruby-to-java) - the 2010 Scala rewrites, mobile traffic moving to the JVM stack, and election night figures
5.  [Artima - Twitter on Scala (April 3, 2009)](https://www.artima.com/articles/twitter-on-scala) - interview with Steve Jenson, Alex Payne and Robey Pointer on the first Scala service
6.  [High Scalability - The Architecture Twitter Uses to Deal with 150M Active Users (July 8, 2013)](https://highscalability.com/the-architecture-twitter-uses-to-deal-with-150m-active-users/) - parts of the write path still running on Ruby in 2013; the Gizmoduck and Tweetypie service names
7.  [Chris Aniszczyk - Evolution of The Twitter Stack (LinuxCon 2013 slides)](https://www.slideshare.net/caniszczyk/twitter-opensourcestacklinuxcon2013) - the Monorail name for the Rails application, and the services built around core nouns
8.  [twitter-archive/snowflake - README (GitHub)](https://github.com/twitter-archive/snowflake) - what Snowflake is and its 2010 first release

Last updated November 28, 2026.

## Scorecard

Worked

Gen 1

A single Ruby on Rails application and codebase on MySQL

Gen 2

Separately owned services on the JVM, written in Scala and Java, on sharded storage

Approach

Move one component at a time behind the running product, starting with the parts under the most load

How long

About four years: the message queue by 2009, tweet storage in 2010, search in 2011, mobile traffic in 2012

Verdict

The engine was replaced while the product stayed up. It took years, and it was never a single project with a launch date.

## More case files

-   [Netscape 6](https://gen2.dev/cases/netscape-6/)
-   [Python 2 to 3](https://gen2.dev/cases/python-2-to-3/)
-   [Firefox Quantum](https://gen2.dev/cases/firefox-quantum/)
-   [Perl 6 and Raku](https://gen2.dev/cases/perl-6-raku/)
-   [AngularJS to Angular](https://gen2.dev/cases/angularjs-to-angular/)
-   [Windows Longhorn](https://gen2.dev/cases/windows-longhorn/)
-   [Digg v4](https://gen2.dev/cases/digg-v4/)
-   [Basecamp](https://gen2.dev/cases/basecamp/)
-   [IPv4 to IPv6](https://gen2.dev/cases/ipv6/)
-   [VB6 to VB.NET](https://gen2.dev/cases/vb6-to-vb-net/)
-   [HTTP/2 and HTTP/3](https://gen2.dev/cases/http-2-and-3/)
-   [K-12 browser rewrite](https://gen2.dev/cases/k12-browser-rewrite/)
-   [Mac OS X](https://gen2.dev/cases/mac-os-x/)
-   [Microsoft Edge](https://gen2.dev/cases/edge-chromium/)
-   [Winamp3](https://gen2.dev/cases/winamp3/)
-   [Slack desktop](https://gen2.dev/cases/slack-desktop/)
-   [Evernote 10](https://gen2.dev/cases/evernote/)
-   [Uber rider app](https://gen2.dev/cases/uber-rider-app/)
-   [HealthCare.gov](https://gen2.dev/cases/healthcare-gov/)
-   [Thunderbird Supernova](https://gen2.dev/cases/thunderbird-supernova/)
-   [Skype](https://gen2.dev/cases/skype-cloud/)
-   [Sonos app (2024)](https://gen2.dev/cases/sonos-app-2024/)
-   [FBI Virtual Case File](https://gen2.dev/cases/fbi-virtual-case-file/)
-   [LinkedIn Inversion](https://gen2.dev/cases/linkedin-project-inversion/)
-   [Netflix to AWS](https://gen2.dev/cases/netflix-cloud-migration/)
-   [TSB migration](https://gen2.dev/cases/tsb-migration/)
-   [Phoenix pay system](https://gen2.dev/cases/phoenix-pay/)
-   [Universal Credit](https://gen2.dev/cases/universal-credit/)
-   [Queensland Health payroll](https://gen2.dev/cases/queensland-health-payroll/)
-   [Facebook for iOS](https://gen2.dev/cases/facebook-native-ios/)
-   [New Microsoft Teams](https://gen2.dev/cases/microsoft-teams-2/)
-   [Dropbox to Python 3](https://gen2.dev/cases/dropbox-python-3/)
-   [Instagram to Python 3](https://gen2.dev/cases/instagram-python-3/)
-   [Discord Go to Rust](https://gen2.dev/cases/discord-go-to-rust/)
-   [Reddit Redesign](https://gen2.dev/cases/reddit-redesign/)
-   [GetPranks](https://gen2.dev/cases/getpranks/)
-   [37signals cloud exit](https://gen2.dev/cases/37signals-cloud-exit/)
-   [IRS Individual Master File](https://gen2.dev/cases/irs-individual-master-file/)
-   [All case files](https://gen2.dev/cases/)
