Twitter: From Ruby on Rails to the JVM [video]
ontwik.com
ontwik.com
It's a competitive advantage for us, we move faster then the rest of the market.
My current startup has a Shopify-like architecture which is what I'm counting on to help me if I ever need to scale fast.
So I think the first question you have to ask yourself when considering scaling is: what is my architecture like?
That is not a scalable solution. Yes, it'll get you up and running out of the box, but as you keep spinning up servers to host each store and it's database you'll have to keep adding exponential resources (hardware, software, meatware) to the problem and keep you from achieving economies of scale.
No, you'd be adding resources at a _linear_ rate relative to the growth of the customer base. The point about economies of scale is true enough but has nothing to do with a lack of exponential growth in costs.
Afterwards, you can spend the time doing it properly when things have calmed down a little.
That's a lot easier than scaling something like Twitter.
> Afterwards, you can spend the time doing it properly when things have calmed down a little.
That'll cost you an extra million dollars to develop and deploy while simultaneously running your existing operations and migrating your clients over to the new solution.
It doesn't scale.
Let's run some numbers though, using your assumptions:
500 VMs @ $179 per customer (business class licence) means a little over $1,000,000. At that point, you'd be right---it wouldn't scale.
However, this is a business and not an HR exercise. So you could easily hire less people, and have less reliability. For a business like Shopify, I imagine their best customers are those who pay the $99 plan, accept a transaction cost, and other limitations. These customers can be piled onto the same VM together, and probably don't have such a huge throughput that a few minutes of downtime means money lost.
If your business has to be up and running 100% of the time, those are the minimal numbers needed to run the operation I've described. I cite a real word example, with real people and real money, the afterwards part if you will, which I'm currently working on to replace, not an hr exercise. And yes, it doesn't scale and it's very costly to replace, and one of the main reasons it was built in such a manner is because the original architect never thought it would have to scale and there are licensing considerations, something rarely mentioned around these parts. Licensing can really fuck things up.
Instead of "Rails doesn't scale" we should say "Rails runs on Ruby which means that it will consume significantly more CPU and more memory* compared to something else"
In my case, 1 extra server (my estimate) was a small price to pay for developer happiness.
* unless you are running JRuby
I'm reading a great book called Service-Oriented Design with Ruby and Rails, by Paul Dix. He states a lot of the issues that our team is running into with a monolithic app. Seems also that these issues can apply to other frameworks outside of Rails (I've run into some of these same issues years ago with Java web apps).
The main point of the book is figuring out how to abstract out various layers of the app into standalone services. I've talked to people about this and a lot of the time they recoil at the fact that you would increase the complexity of the app by adding yet more parts (services) that require separate machines, deployment dependencies, and their own data stores. However, looking at big sites like Amazon or Twitter shows how one needs and can break apart their systems to make it easier for developers to focus on particular pieces as well as increase system performance.
I'm going to be joining a new startup this year as the technology lead and all these things are on the table. I'm evaluating node, some NoSQL dbs, some cloud paas', etc. I'm also going to be designing from the beginning fast fail and services - or at least an architecture that makes it fairly easy to start migrating parts of the system over to their own standalone services should the need arise. I don't think you can plan for everything, but with the way technology is moving forward and the tools available today, you need to keep SOA at least in the back of your mind.
"If you can make up a website that has a higher traffic than Twitter ... it's a great success of business ... so you have money ... so you're safe to hire the Java programmer to replace it. [laughs]"
http://ontwik.com/ruby/ruby-2-0-what-we-want-to-accomplish-i...
We've migrated some key parts out to HTTP services written in Scala, Java, or node.js.
Ruby will give you a significant time to market advantage especially if you are a startup.
If twitter has (some of) the best ruby developer (mentioned somewhere at the end of the video), why have they neglected JRuby? Why is it no option? For legacy code with native extensions this makes sense. But is jruby slower, more memory hungry on the JVM then scala or clojure? I always though that JRuby was one of the more performant languages on the JVM?
Apart from that it was an interesting talk.
http://shootout.alioth.debian.org/u32/benchmark.php?test=all...
But citing the Alioth.Debian benchmarks? Really?
Dude, take a look at the source-code of those benchmarks sometimes -- they are completely useless ;)
Say what you think is wrong with the source-code of particular programs.
You think the Ruby code could be faster, and thus the comparison is skewed? Go ahead and help everyone understand by improving it.
I've been using rails for almost 7 years now (holy crap) and run a medium-sized site on it. It works just fine, but if I were starting from scratch today, I would still use Rails, but I'd run it on JRuby.
I doubt their story would have been much rosier if had they gone with Spring MVC, Hibernate, and Oracle from the start.
The minute you start moving away from CRUD based application design and moving into SOA, you're already signing up for a significant rewrite, even if you stick with the same platform.
Punch Line from Link:
"There’s a very real chance that invokedynamic could improve JRuby performance many times, putting us on par with our statically-typed brothers like Java and Scala. And that means you can write Ruby code without fear. Awesome."
A little off topic: as a consultant it seems like the demand for Clojure was been tremendous: Clojure is a nice language and very performant. It will be really interesting to see how much large speed improvements in JRuby will cut into Java's, Clojure's and Scala's developer market-share.
http://anonscm.debian.org/viewvc/shootout/shootout/website/w...
* Summize brought Scala
* BackType brought Clojure
Has anyone noticed that pattern elsewhere?
As a pragmatic approach, a half century of software engineering says that you should write the code first and worry about making it faster only if it is too slow. Donald Knuth is right: Premature optimization is the root of all evil. Don’t merely let the VM performance metric blind you to this fundamental truth. If you are chasing for a performing language, Java/Scala is not your ultimate solution, C/C++ is, even Erlang.
I actually don’t see a problem with “performance” emerging as the requirement in the Ruby world sooner than others, say Java/Scala, because this “sooner” is very contextual and depends a lot on the implementation. To give you more info, GitHub is on RoR since it started, and till now they haven’t hit the so-called “Rails does not scale” point ( http://teachmetocode.com/podca... ). So are many other projects. Besides, think about Twitter, they only recently try to port everything to the JVM, after Rails has served them a couple years. All these facts tell you, this “sooner” may never happen to your own app, and most importantly, Rails can scale, although it may not scale as well as others! But once you hit the point where Rails, or Ruby in general, doesn't meet your performance requirement (assuming you are lucky enough to build another Twitter), do what Twitter suggests you to do in the video. Is that too late? Not at all. Because by then, you have the resources to do whatever you want, even inventing a VM that is more performing than JVM.
To summarize, the Ruby VM was fast yesterday, is still fast today, and will be faster tomorrow. In 90% of the cases, it's just fast enough. Do I need the performance gain by switching to JVM? Don't know yet. It'd be better to let the market drive you. Does Rails provide the agility I want to start a project? 100% hell yeah!
So your inbound load is 7000 tweets/sec or roughly 250 MBit/s (assuming 4k per tweet). Then you fan that out to (assuming) 20 append-only mailboxes on average.
Perhaps my assumptions are far off, but I'm only arriving at a couple GBit/s here and a low two digit number of terabytes/storage per year.
This sounds like "a couple racks" to me, not like "a couple datacenters".
http://www.slideshare.net/nkallen/q-con-3770885
Now, at the time they were doing peak 2000 tweet/s. The fan-out was 1.2M deliveries a second... So if we go with the current 600:1 ratio at 7000/s, that's about 4.2M/s. I actually know it's much higher now since I work there but other things to consider is we have a large data warehouse, search, API, pipelines to external parties for the firehose, logging at terabytes an hour, in-house metric collection doing 3M writes/s, etc.
http://www.scribd.com/doc/59830692/Cassandra-at-Twitter
It add's up very fast.
People also have opinions about java(scala/clojure) vs javascript from a language preference standpoint. I think it is too early to tell what impact this will have.
However, many developers I know seem to have a strong distaste for Java, the JVM, and the ecosystem around both. I think several of those folks would look to node, erlang, or possibly even golang (if it gets faster) simply to avoid using java.
Back-end developers seem to (maybe?) prefer to use Java.
People are still using C and C++ to write low level code. Databases, package managers, games, etc. Then there are the 'application developers' as you named them, writing http service endpoints, web apps, and the like.
It seems java still owns the colossal corporate stacks. I hear things like "it is easier to hire" and "java is faster/better for extreme large scale". If you think about all the languages and tools available, only the first makes much sense.
* C/C++/D is faster than java.
* statically compiled code is easier to deploy.
* Erlang is arguably more scalable than java.
* Haskel/Ada is 'safer' than java.
* I think several languages are more fun to write in than java. Ruby, python, golang, coffeescript, etc, etc.
So java may not be the best language for large scale, but maybe one of the best or good enough? When combined with the first point of ease of hiring, I can certainly see why large companies are attracted to it. If your language of choice lends itself to your workers being more easily replaceable, then as a company that is probably better/safer.
Other than that, I can't see why someone would prefer to use java. I don't work in/at/for huge companies though.
I admit that my own personal 'java bias' is based on dated interactions with java. Whenever I hear 'java' I think: good performance (vm), eats memory like candy, painful ecosystem of xml files and outdated/abandoned random libraries. I have tried dabbling in scala, and while I enjoyed the language to a fair extent, I still found myself wrestling with the JVM and the ecosystem (library version incompatibilities, obscure compiler errors, namespace wrangling, etc).
I don't deny the reality that people are still writing C/C++ code in the field of embedded devices, games, something that requires fast performance with a very low memory usage. On the other hand, there are a few NoSQL solutions built using Java: HBase, Neo4J, Cassandra.
In some cases, JVM Hotspot optimizes code on-par with C/C++. I don't know much about D performance. If the speed improvement is not night-and-day for projects other than being mentioned above, and if writing readable code is much better in Java, I'm not sure if we should compare C/C++ vs Java. On the other hand, many people seem to come out and say that Ruby is _very_ slow. Is it heaven-and-earth slow?
There are advantages and disadvantages of compiled vs dynamic code when it comes to deployment. It all depends on the tools and ecosystem too sometime.
How is Erlang more scalable than Java? In what area? horizontal vs vertical scaling? developer's productivity (or team performance) scale? performance? speed? Erlang seems to excel in a niche area (in a positive speaking).
What about Haskell/Ada, how are they safer than Java? Do they have better type-systems? handles NULL better than Java? Bulletproof from developers? detect more bugs?
Keep in mind that Java ecosystems have grown and matured a lot since 2004. The tools and libraries are staggering. Most of your concerns are no longer relevant except "eats memory like candy" in most Java desktop apps. Having said that, have you heard about Java ME? that thing runs in mobile devices albeit a different distribution of JVM.
Outdated/abandoned random libraries seem to happen in our neighboring ecosystems: Ruby (and Rails).
I have to admit that sometime other languages are more "fun" to dabble with. I use Python and Ruby. I like Python because I don't have to argue when it comes to code-style. Pythonic (PEP-8) or GTFO. It's not that I hate innovation or artistic coders, it's just that I'm a discipline person. Best practices in most cases, pragmatics when needed, hacks when the world ends tomorrow.
Companies chose Java for varieties of reasons and yes, one of them is the available pool of talents. I'm sure we all have heard the old phrase "enterprise developers". Some of them are bad, while others are quite sharp when it comes to the typical enterprise stack. Some of them can design systems/libraries quite well. Spring Framework comes to mind. Google Guice, Google Guava, Android are next (yep, crazybob used to do EJB and enterprise Java stuff yet he's one of the sharpest Java dude I've known).
I noticed that some of the well-run enterprise systems do have a better infrastructure planning thus forcing people involved around it to know better when it comes to certain technology choices. I'm sure there are web startups out there that just keep on hacking PHP code and use MySQL without having plans for backups, recoveries, etc.
Of course these are anecdotal experiences of mine.
> On the other hand, many people seem to come out and say that Ruby is _very_ slow.
> Is it heaven-and-earth slow?
Comparatively, I would say yes. Granted, most of the time it won't matter because you are waiting on IO (disk/network), but if you are doing cpu intensive work, it is slow and you probably need to drop down to C or offload that work to another service. > How is Erlang more scalable than Java? In what area? horizontal vs vertical scaling?
> developer's productivity (or team performance) scale? performance? speed? Erlang seems
> to excel in a niche area (in a positive speaking).
My guess would be in single server scalability. Erlang's write-once variables and actor model, combined with a good VM ("green processes") make it very single-server-scalable (verticle). It also has good built in node-to-node communication mechanisms (horizontal). Performance is probably slower than Java though. And I imagine the developer pool is much more limited than that of Java. > What about Haskell/Ada, how are they safer than Java?
> Do they have better type-systems? handles NULL better than Java?
> Bulletproof from developers? detect more bugs?
I meant safer in the type-safety sense, yes. There are also classes of static analysis tools for both. Granted, my knowledge of these languages is quite limited.I certainly see your points (especially about liking the code hygiene of python), and agree that Java is not going anywhere soon. I guess I don't understand why a startup, or individual developer, would choose Java over other languages, even other languages on the JVM, for new projects.
Thanks for the good discussion. :)
Checkstyle is another tool that I use since I'm kind of the annoying dude when it comes to code-style. (Have you seen GWT API code? it's like written by one person as opposed to a few developers with different perceptions of "readable" code. I like that kind of thing).
There are a few reasons why startup/individual dev would choose Java:
1) Previous experience in Java
2) Java fits better for the type of problems to solve (intensive computational that requires Hadoop like infrastructure)
3) Emotionally attached to static/compiled language with nice IDE so that one can navigate the source code easily whether the code base is large or small (sometime not all decisions are rational and I'm okay with that because developing software requires more than technical skill; it also requires passion).
4) Marketing (if you're targeting the enterprises). Zimbra, Jive Software, Compiere, Alfresco, Day software, Liferay, Salesforce used to be startups.
Java ecosystem seems to learn and grow in a much better speed thanks to the following actors:
- Rails (Spring Roo, Spring MVC, JPA 2.0, and possibly MVC framework from the upcoming JEE releases)
- C# (Java 7 new features, Java 8 closures/lambda. Yes, Lisp does this first, but I think C# forces Java to implement closures more than any of its competitors).
- REST/JSON/WS (Check out the latest JAX-RS, supports REST, JSON, XML, Atom-Feed, and JAX-WS)
- I/P/SaaS + Cloud Computing (Targeted for Java EE7, deployment, infrastructure to support multi-tenant, etc).
NB: Just so that I don't sound like a Java fan-boy, I use Java by day but I use and help to promote and organize Python community overseas (of course by not comparing Python vs Java :)).
Things changed.
Perhaps I was misusing the word "back-end".
When I refer to app-developers, I'm pointing toward people who build web-apps using Struts, Spring, JEE, EJB (I see where you think that back-end means completely EJB/Service/Hibernate).
The non-app-developers seem to keen on building infrastructure around the Java ecosystems:
Hadoop, HBase, Cassandra, ZooKeeper, custom server using Netty or Apache Mina. Or even building platforms such as GWT, Android.
Like he states at the end of the video, when describing the 7000+ tpm during the WWC:
"...we do things like Forex spikes upon our standard baseline growth. So right now the JVM is really the only mechanism that we can build upon that gives us the flexibility to do something like that."
when you need many concurrent users then dont use ROR but use JVM or C++ or Scala instead,
if you need to build a fast prototype build on ROR or PHP etc.