Meditations on programming, startups, and technology
New Relic

On Rails and DB2

James Governor wrote an interesting post entitled “On douchebags, DB2 and Rails: DHH not pragmatic enough?”. It’s partially in response to Jeff Atwood’s article “Douchebaggery” which, in turn is a reply to an old post by David Heinemeier Hansson. So please excuse me if I limit the entertainment value of this post by not calling anyone names. :)

Amongst a few sensible comments, James also argues that David may not be nearly opinionated and pragmatic enough after all:

What’s bothering me though is that perhaps Hansson isn’t opinionated enough. You see Rails targets MySQL. MySQL is the Rails database. Forget all the configuration crap and just use MySQL. There is no need to consider other database platforms. LAMP may or may not be a literal but MySQL is utterly embedded in the Rails way. In Rails database is not a design decision, its a given.

As most of you will already know, Rails was extracted from a real web application called Basecamp. This approach is thought to be the first sign (scientists believe there are 37 of them :-P) that we are dealing with a pragmatic framework. Its features and design choices weren’t defined a priori by David, but they were implemented to satisfy particular needs (and opinions) which Hansson and his team had, while developing database driven web applications.

When analyzed under a proverbial microscope, one sees that Rails didn’t actually invent anything new. Neither the MVC paradigm nor the Active record pattern were especially innovative. They’d been well known for years in the Computer Science world and even adopted (to a certain extent) within the enterprise realm. Yet, Rails was a revolutionary piece of software. What Rails did was to tie all the loose ends together into a neat, tidy package. On top of that achievement, it clearly favored simplicity, pragmatism and developer productivity over anything else. Forget about repetition and countless XML configuration files, it was opinionated software that made web development, or at least most of it, rather trivial. Less choices for the developer (the Paradox of Choice comes to mind) turned out to be a significant gain in terms of “ease of use”, which in turn bolstered Rails’ adoption.

Rails wasn’t supposed to be the answer to all web development needs everywhere – just to most of them. This means that the making of such a DSL involved a lot of assumptions. In turn, there are people who don’t use Rails due to these assumptions, and projects where adopting Rails wouldn’t probably be the smartest choice either. But Rails worked for David and 37Signals, and in doing so, it also happens to work very well for thousands of other developers around the world with similar development needs, who’re facing analogous challenges. David did his best to create a usable and enjoyable web framework, and succeeded spectacularly in responding to the needs of most web developers.

For this, Rails constantly gets accused of being far too opinionated. How many times have we seen comments about the lack of prepared statement support, that there’s no connection pool, no thread safety, no unicode, about deployment issues and so on. James’ comments are interesting because they’re entirely unusual. He’s arguing that Rails is not opinionated enough, and that in itself, is an opinion worth replying to (and not simply because he explicitly called upon my views on the subject at hand within his post):

Why in the Getting Started section of the book, do the authors even mention DB2 as a potential target database, even if its just an aside (Rails does allow exceptions it just doesn’t like them)? I mean if a DB2 bigot came to ask Hansson for a job at 37Signals he would be shit out luck wouldn’t he? You can imagine the laughs- “this guy wants to back end Rails apps with DB2 – what a ***tard.”

I know Anthony would disagree with me, and arguably Rails abstracts the database decision, so Rails is not tightly coupled to MySQL. But that’s not the point – we’re not talking about JDBC here.

I’m pretty sure that David doesn’t care about shared hosting, prepared statements, support for stored procedures, JRuby, DB2 or the “enterprise world”. It’s not his way of creating and going about web development, plus he really doesn’t have any need of these for his own purposes. Therefore don’t expect support for these points from him. However, that said, David is also being fairly reasonable with those who think differently than he does.

David’s message is: if you need these type of features, then please by all means, go ahead and implement them yourself. Rails’ core team has enabled the development community to extend Rails to fit a different kind of bill. While the policy in terms of accepting patches may be strict and not particularly welcoming of every single contribution, the plugin architecture coupled with Ruby’s flexibility and extensibility, allows the injection of substantial features which in turn significantly affect Rails. There are limits of course, and some people even preferred to create a similar framework from scratch, because they found it easier and neater to do so than to completely restructure and refactor Rails’ core.

David clearly favors opinionated conceptual integrity and the act of defining a set of sensible conventions over abstraction/modularity/extensibility, which would be regarded highly by those who require enterprise features or view web development in a markedly different way. He did not intentionally set out to block these things either though, and that’s worth remembering. He proposed his take on things, but he certainly did not impose it on anyone else. Doing so simply would not make sense (and might have required more work on his part in some cases).

Take ActiveRecord for example: it’s not a perfect abstraction, given that its Ruby implementation makes several MySQL centric assumptions in regards to SQL generation, which makes development of alternative adapters for other databases less than trivial (particularly for so called enterprise databases). But it’s still essentially a database agnostic pattern that would be almost harder not to implement as such. David’s implementation poses a few challenges here and there, but we’re still very much within the realm of possibility.

David might only use Rails with MySQL, and he may only slightly care about the subset of features which are common to all databases (including SQLite, the current default database) and nothing more, but at the same time he clearly realizes that we are not all Davids. He’s not willing to warp his creation in order to make everyone happy. That’s not David’s style. However, if other databases or options are available to Rails developers, why not mention them as a testament of the interest surrounding Rails?

The fact that DB2 is a viable (free of charge) option for Rails developers doesn’t affect the Rails core team in a perceivable way, and it still offers the possibility of using Rails to a whole new segment of programmers. Which bring us to the next point:

Anthony says “an increasing number of Rails developers adopting DB2 as their database of choice”. I would like to know more about this “increasing number” from Anthony [...]

While perhaps not the most vocal bunch in the blogosphere, there are many developers and companies interested in DB2 on Rails. In my experience, I’d say that there are three main likely/common scenarios (of DB2 on Rails users):

  1. Companies who have already widely adopted DB2 in their infrastructure and are now considering Rails for some of their projects. The developers involved are usually very excited about DB2 on Rails, because it means that they have a rare chance to use Ruby/Rails rather than Java/J2EE or similar technologies, with a data server that they already have a good understanding of. While some web developers choose the framework first and consider the database at a latter stage, most companies don’t work that way.
  2. Developers who have DB2 skills and are looking for a good framework for developing web applications. They have no reason to use any other database but DB2.
  3. Companies or developers who understand the technological advantage offered by DB2’s features (e.g. utmost speed, pureXML, compression, replication, high availability, affordable 24/7 support, etc…) and therefore choose it for their Rails based projects.

Rails doesn’t exploit advanced database features, and as a result, it doesn’t provide any further compelling reasons to adopt other databases aside from MySQL. It takes a discerning developer to realize that DB2 has much more to offer and that there are concrete benefits to adopting it – even when developing with Rails.

It’s also true that working with an independent adapter in Rails will generally be less “comfy” than using SQLite/MySQL/PostgreSQL. For example, certain tasks are not implemented for DB2 by the Rails team, and as such won’t be available. But it’s a small price to pay. In order to change this, I decided to start a project in my spare time (not an IBM project), called DB2 Extended. From the RubyForge description: “db2_extended is a Rails plugin that extends support and enhances the user experience for developers who adopt DB2 as their backend for Rails applications”. This project is currently empty, but I hope to perform the first svn commits over the weekend. I’ll start with simple things that close the gap (like making rake db:create work for DB2) and incrementally, I’d love to throw in DB2 specific functionalities and enhancements as well. Being a personal, open source project, I will more than happily accept patches and contributes from the DB2 on Rails community. Hopefully in a short period, we’ll have a plugin that makes web development with Rails and DB2 even more fun and productive.

As usual, these opinions are only mine and don’t necessarily represent my employer’s (IBM) positions, strategies or opinions.


If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

receive my posts by email

9 Responses to “On Rails and DB2”

  1. Robert Hulme says:

    I think you’ve fundamentally misunderstood how Free Open Source Software development works. The drive behind the development of any code is either that someone is being paid to write it because a company wants it, or more often because the developer themself wants the new feature.

    If DB2 support isn’t very good in Rails and you want it to be better it is up to you to change it. The rest of the Rails community is under no requirement to produce software that supports your requirements, that’s up to you.

    As it happen I’d like to chip in and say that I am using Rails on a project with my employer where I have to deal with a complex schema with billions of rows and composite keys, and it’s a veritable cakewalk to do that with ActiveRecord. If DB2 support falls far behind Oracle support that may indicate something about DB2 and / or the number of DB2 users / developers who have an interest in Rails.

  2. tim says:

    SQLite may be the new default, but I disagree that it’s the “path of least resistance”. MySQL is still the best-supported RDBMS by ActiveRecord by a mile, and not actually that hard to set up (even though I hate it as an RDBMS).

    For fun, try creating a table with :id=>false (and your own id column) in SQLite, and then watch AR break left-and-right.

    And yeah, I’d file bugs about all of these, except most of the things I’ve run into already have 3-year-old bugs in the Rails trac.

    You’re right in that they really only care about the “subset of features which are common to all databases”, but unfortunately this feature set is both undocumented, and much smaller than one might expect.

    (Disclaimer: I’m just bitter because I tried to get a production Rails app, running on MySQL, to run its tests in SQLite. After monkeypatching a dozen SQLite bugs — most straight from unapplied patches in Rails’ trac — and no end in sight, I gave up.)

  3. Hi Tim,

    you’re absolutely right about the fact that MySQL is still the path of least resistance. I’ve removed my remark about SQLite from the article. :)

  4. Robert, calling me names on Reddit is not very nice or mature, is it? Even though your comment comes across as a trolling attempt (in all fairness), it wasn’t published right away only because all comments in this blog are moderated.

    I think you misunderstood my article. I am arguing the same things that you do in regards to Open Source contributions.

    Also, DB2 support for Rails is very good, and there is no reason to believe it’s behind Oracle at all. What I’m talking about here is my attempt, through a plugin, to make the user experience even better/easier/comfier and closer to that experience by people who pick MySQL as their backend. A plugin that will also implement support for DB2 specific features, and that I will develop in my spare time, with the optional help of the DB2 on Rails community.

  5. Dan Kubb says:

    Antonio, you may want to take a look at DataMapper (http://datamapper.org) if you’re interested in helping out with a Ruby ORM. In many ways its similar to ActiveRecord, but I believe it has a better overall design. Right now a few people on the core team is working on DataObjects (DO), which are basically Ruby/C drivers to the underlying database engine. Currently MySQL, PostgreSQL and SQLite are supported, and I would bet they would gladly welcome a DB2 driver. Once DO is completed, DM should be the fastest Ruby ORM available.

  6. Robert Hulme says:

    I said you were lame because you approved Tim’s comment (which was made 3 hours afterwards) but not mine. Then I pointed out on a site you can’t censor (Reddit) that you were using comment moderation to hide comments that disagreed with you, and lo and behold my comment appeared.

  7. Robert, I first provided an answer to Tim (it was a quick one) and approved his comment. I was then writing a much more articulate reply to yours. When I saw that you were accusing me of censoring you, something that I don’t do unless comments are inappropriate (e.g. vulgar or spammy), I published your comment right away and proceeded with writing a different kind of response afterwards (which is published above). Those who follow this blog know that negative comments are always published and replied to.

  8. Nuno Job says:

    I made a similar article today :P I even quoted the DB2 extended project.

    By the way that discussion brings nothing to the site or the articles. Lame is coming here to read the article and get all this garbage. So if I was António I would have censored all of your comments – for the sake of the non troll users that read this blog.

  9. Lester says:

    I have been coding with rails and to date I have not had much problems with it. It helps i think to have some background on basecamp.

  10. [...] On Rails and DB2 When analyzed under a proverbial microscope, one sees that Rails didn’t actually invent anything new. Neither the MVC paradigm nor the Active record pattern were especially innovative (tags: rubyonrails) [...]

Leave a Reply

I sincerely welcome and appreciate your comments, whether in agreement or dissenting with my article. However, trolling will not be tolerated. Comments are automatically closed 15 days after the publication of each article.

Current ye@r *

Copyright © 2005-2014 Antonio Cangiano. All rights reserved.