Learn more about Engineering at Procore on our new site.

Roda vs. Sinatra For Small Projects

I’m a hacker. I like to build things and get stuff done. Also, I care about efficiency and performance. Even though I use Rails all day long, it feels like too much for my own personal projects.

When I’m hacking on some code for fun, I don’t reach for Rails. Lately, I’ve used Roda.

What is Roda?

Roda is a tiny web framework written by Jeremy Evans, who also is the man behind one of my other favorite ruby projects - Sequel.

Roda is cool for two reasons - server performance and its novel routing tree structure. They are related ideas.

The routing tree structure for Roda is cool. It sets up a tree to check routes against. That means you can nest routes or include routes easily without compromising performance.

You also can DRY up some of your code by including your routes as separate files or by including things like authorization higher up in the tree instead of in each route.

It makes structuring your projects clean, but flexible.

The performance from Roda is excellent. Based on my benchmarks, it is one of the fastest web frameworks available for Ruby.

Performance means a lot to me because as a user I notice slow apps. I want what I build to be as fast as possible, while still being fun to write.

Let’s take a look at a simple hello world example…

Roda Example

require 'roda'

class App < Roda
  route do |r|
    r.get '/hi' do 
      "Hello World"
    end
  end
end

This code does almost nothing. What’s great about that is on a small personal project, you don’t need a lot of setup or structure to start building something useful.

To me, on a small project that might only have a few endpoints, the MVC structure of Rails is too much. I’d rather get straight to hacking. Keeping everything in one file can be a good thing.

Also, when your project gets too big for its britches, it becomes obvious to break it into more files.

Why Not Sinatra?

Sinatra is great, and it’s one of my all time favorite software projects.

My problem with Sinatra is performance. I always thought it was a lot faster than Rails, and it is. It’s just that other projects like Cuba are way faster.

After writing the Ruby Web Benchmark Report, I realized that Sinatra wasn’t as fast as I wanted it to be and I started looking at Cuba and Roda.

Now that I’ve used Roda on a few small projects, it’s grown on me and I enjoy it a lot.

Also, Roda can be nearly 2.5x faster than Sinatra, so that’s pretty nice too.

Roda Isn’t Perfect

Not every project is a great fit for Roda. I use it on small things where I’m the only developer. I wouldn’t try and get my team at Procore to use it unless it was a small, isolated utility.

Documentation is good. However, it’s a very small community.

Roda is a web request router, not a full blown framework. That means solving your own problems sometimes. I enjoy that, but a lot of people accustomed to Rails might not enjoy this approach.

Ultimately, I enjoy Roda a lot as a break from the daily grind. It’s fun and worth checking out if you are a Ruby developer.