FreshBooks

Search


API Calls

Resources

All blog entries posted under FreshBooks

How To Run a Stealth Rails Application

by Justin in FreshBooks on April 1, 2009

I’ve got a little secret to share about our technology stack here at FreshBooks.  Although by all appearances we are just another PHP shop, FreshBooks has actually been powered by Ruby on Rails for about three years now.  Here’s how we did it:

Back in late 2005 when Rails hit the mainstream, we were eager to do a complete bottom-up rewrite.  However, management was rather concerned that our customers would react negatively to such a radical technology change.  Would people trust their financial data with an unproven web framework that had only recently been publicly released?  To stay on the safe side, we decided to disguise the new Rails app to appear as though it was still the old PHP version.

Thanks to Rails’ flexibility, this was surprisingly easy to achieve.  The heart of the disguise is a single line added to our routes.rb file:

  map.connect ':fake_filename.php', :controller => 'php', :action => 'dispatch'

This takes what appear to be requests for php files and sends them over to our PhpController controller.  In the dispatch action, we lookup the “filename” that was requested and map it to an action and a controller to actually handle the request.

class PhpController < ApplicationController
  FILENAME_ROUTES = {
    'about' => { :controller => 'about', :action => 'index' },
    'pricing' => { :controller => 'pricing', :action => 'index' },
    # ...snip…
  }

  def dispatch
    redirect_to :controller => FILENAME_ROUTES[params[:fake_filename]][:controller], :action => FILENAME_ROUTES[params[:fake_filename]][:action]
  end
end

Sure, there is a little performance hit with the redirect, but we’ve found that most users don’t really notice.

We use Apache (with mod_proxy) to send requests to Webrick application servers.  Although it uses a lot of memory, our Webrick cluster has held up surprisingly well.  We’ve been meaning to switch to something more modern like FastCGI + lighttpd so we’ll keep you posted.

Anyway, I hope that this hasn’t come as too much of a shock to anyone. We’ve been running this setup for quite a while and felt it was time to come clean (although some people have suspected that this is what we were up to for some time now).

7 comments

Introducing Mike

by Mike G in FreshBooks on September 25, 2008

Allo Freshies!  My name is Mike (no, not McDerment), and I’ll be one of your API developers.  I say “one of your API developers” as we have a whole team now (there are two of us).  So be prepared for updates big and small.

Since I’m the second Mike in the office, I’ve been barraged with nicknames since I joined up.  Because my last name is Gauthier, there are a few variations I will respond to.  Mikey G or MG would work.  G-man?  Michael?  Embarrassing.  But since Mike McDerment doesn’t really post on the Developers blog, I can hope and dream of being just ‘Mike’ again.  We can keep that between us.

From here on in, we intend to post more frequently than we have.  Our last blog post was in June, and that’s just not cool.  Also, please feel free to get in touch with us via the developer forum.  My teammate Dan (introduction forthcoming) and I will be actively monitoring our community and addressing developments and concerns both here and there.

0 comments