1

I've been programming in Rails for about 7 months now. Mainly an app to aministrate a database, you know, clean up, update, delete, find orphaned entries etc.

I have an API that talks to our desktop programs written in PHP. We now find ourselves wanting to move everything over to Ruby. This API needs to be lightning quick and will not have any views or HTML pages of any sort, it will only communicate with our apps via JSON, sending and receiving data that the apps will then display and work with.

So, the basic question is, should I learn Sinatra and Padrino (with ActiveRecord) and build the API with them, or do it in Rails?

If I use Rails I could keep a lot of the code I have or even use the existing code since all the tables are the same (database is the same) and just write more methods for the API.

The downside I see to this is twofold:

  1. It means the code is harder to manage and read because now we have the API bit and all the maintenance bit.
  2. It would mean that the same Ruby app is doing double work so the API would not be as fast as if it were running in another, separate Ruby app.
  3. Already the Rails app is not great speedwise but I suspect this has more to do with our hosting solution than Rails itself.

Learning Sinatra and Padrino might be more work, but would lead to cleaner code and a separate Ruby app for the API and another one for the maintenance which sounds nicer.

But I don't know anything about Sinatra and Padrino, is the footprint and speed really that better than Rails?

I would greatly appreciate opinions from people who have actually used both Rails and Sinatra with Padrino on this.

Cheers.

kakubei
  • 5,321
  • 4
  • 44
  • 66

2 Answers2

5

Sinatra and Padrino are not automatically faster than Rails. They are just smaller than Rails (and supply the developer with a smaller, more focussed toolkit). Application speed mostly depends on your code (and algorithm). The same is often true for elegance, maintenability and other aspects.

If you already have good, maintenable code that runs on Rails, most likely you should just improve it. Make it faster with a good hosting/caching solution and keep it elegant and maintenable with refactoring.

Nowadays, both Rails and Sinatra offer very good support for the development of RESTful webservices and, more generally, for the development of UI-less APIs. Rails is just larger and takes more time to be tamed but, luckily, you do not have to study and use all of this behemot to get your job done. An application running on Rails can be as fast and elegant as one running on Sinatra because the Rails subset actually used to handle REST requests is as small and elegant as the whole Sinatra framework. Hence, application speed mainly depends on your code and on your hosting/caching choices.

On the other side, you ought learn Sinatra and Padrino in any case. These frameworks are two of the most elegant and fascinating pieces of software I have ever seen. They absolutely deserve your attention. Just keep in mind that Sinatra, used alone, is normally not enough for anything more complex than a UI-less RESTful API. Most likely a real, full-blown web application will require Padrino.

AlexBottoni
  • 2,237
  • 20
  • 24
  • Thanks Alex. If there isn't such a difference between Rails and Sinatra with Padrino, where would you use one and where the other? – kakubei Oct 02 '12 at 08:33
  • I usually try to use the least amount of framework complexity required by the task at hand. For a "naked" RESTful webservice (no UI) I use Sinatra. For small/regular web sites, I prefer Padrino. I use Rails only if the project deals since the beginning with a large, feature-rich, complex web application. Beside this, Rails offers you a lot of pre-built features and a lot of easy-to-use plug-ins so in many cases it is easier/faster to use Rails than to re-create everything from scratch. – AlexBottoni Oct 02 '12 at 11:42
0

If you have an existing Rails app already, it might be easier to port it over to rails-api. It's basically just Rails but stripped of all components used in making UIs.

I haven't personally used it but I was evaluating it for a project a few months ago.

Noel Llevares
  • 15,018
  • 3
  • 57
  • 81
  • Hmmm... That does look intriguing, but just by reading their github Readme I can't really see the advantage of using that over Padrino. Can you? – kakubei Oct 11 '12 at 14:54
  • It's going to boil down to one's preferences, I think. If you're already good with Rails and you are pressed for time, it might be better not to learn something new at the moment. – Noel Llevares Oct 12 '12 at 19:30
  • I have been using it for 3 months now in production and I have to say that Rails-API is really nice to work with and does the job. – yagooar Oct 01 '13 at 18:08