Migrating from Rails to Rack

by Christina Chortaria, Carolyn Cole, Ryan Laddusaw, and Jane Sandberg

Technology Decision

Allsearch is a search application with a VueJS frontend and a Ruby backend. The backend was originally in Rails, but we decided to move it to Rack. We chose Rack because it allowed us to do an in-place conversion – Rails applications are Rack applications already, we just needed to remove and replace the Rails pieces; no changes were needed to our deployment process. Deepening our understanding of Rack would also help us in our work with any Rack-based application, whether it is Rails, Hanami, or just Rack. Rack is quite simple and does not provide every feature that Rails does, so we supplemented Rack with:

Conversion Process

Many Rails features had one-on-one replacements that you can adopt incrementally. We were able to do the following without much friction:

Replacing the Rails router was an incremental process. We first used Rack::Builder and its map method to create a Rack application that routed to all our Rack Applications, and pointed our Rails router to this new “Router” application. Rails’ router is tightly integrated into the built-in Rails initializers. Before we could completely replace the Rails router with our own, we had to replace the Rails.application.initialize! call to a new initialization process that is more selective about which of Rails’ built-in initializers are run.

Zeitwerk is a nice autoloader. However, we can’t use our own autoloader and the Rails autoloaders at the same time. The answer is the same as the routing: replace Rails.application.initialize! with a more selective initialization process that does not create Rails autoloaders.

Successes

Challenges

Key Concepts

Here are a few key concepts that we now use in our application:

How has it been going?

It has been 8 months since we finished the migration, and it has been working great so far! Please feel free to try out the Allsearch application or see the project Github.