Does Rails Scale?
Join the DZone community and get the full member experience.Join For Free
first, the short answer: damn right it does.
twitter had to quit using it because ruby is so slow
it is well known that around 2008 twitter moved their job backend from rails to scala. to me it seems they absolutely made the right choice. twitter had way outgrown the version of ruby it was on and they needed a different solution.
keep in mind that ruby 1.9 came out a year later in 2009. the performance characteristics between 1.8 and 1.9 is huge. just look at this graph from zendesk's report of moving from 1.8 to 1.9
in addition, rails had no support for asynchronous jobs at the time. rails would not have done anything to help job processing, so moving to scala probably made a lot of sense. today, we have resque and sidekiq which make the process much cleaner on the code side.
but ruby is slow even in 1.9
it's not a fast language. however, that rarely matters. the hard part about scaling an application is proper architecture, solid caching and cdns, the right database for the job and so on. it's more about external resources than the code in the app. the runtime of the language rarely becomes an issue. the goal is to leverage existing tools in order to do less work on the web stack.
in most scenarios, you're scaling concern will not be waiting on the speed of ruby, but the i/o. when ruby is really able to leverage its fibers (such as in em-synchrony ), we'll start to see node.js levels of performance.
none of this matters
i wouldn't call twitter unsuccessful. they did build their product and eventually found the right architecture for them. i doubt the engineers at twitter think that going with scala right off the bat would've been the right choice. using rails, they could build the product quickly. they could change it in order to build the product in a way that was successful. rails empowers the developers to change direction without a lot of code change.
not only can developers alter features, but the same is true on the backend as well. i've worked on a system where we swapped database backends from mysql to postgresql with almost no code change. another project where we included advanced caching layers without modifying existing models. in the same way that ruby allows rapid product changes, the ability to rapidly alter architecture changes ensures scalability.
these are all changes that would've been so prohibitively difficult in my .net and django days that we would've just greenfielded a new project.
rails is not all roses
while rails does a lot of things well, there is one part of scaling it does not do well. the human issue. rails encourages the 'monorail' architecture. projects approach the size that become difficult to work on. no single engineer will understand the project from beginning to end. new engineers will be lost in the project and feel unproductive. bugs might arise out of seemingly disconnected parts of the code-base.
a more disconnected architecture has many pros in a large system. engineers will feel more productive as they can really own their project. the knowledge needed to be productive will be much lower.
square, groupon, yp, tapjoy and others have all experienced these growing pains. they've also all moved to a service-oriented architecture (soa) to solve these issues. one of the biggest issues rails has is with easing that transition. now that it's been happening regularly, i think we'll start to be able to identify patterns and enhance the framework to support it, however.
that doesn't mean you should go for soa right off the bat though. i believe moving from a monorail and then breaking the system apart is the correct approach. with any platform, soa is simply a more complicated architecture. you also won't know what services there actually should be until you've got a large codebase.
so yes, it does scale
even given the faults on the monorail problem, rails scales beautifully. between the speed of ruby 1.9, the fact that most of our work is i/o heavy, and the ability to alter the stack: it certainly scales.
Published at DZone with permission of Jeff Dickey, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.