Sinatra as a Web Service Server
Recently we launched an internal project called Giv.to. Giv.to is a URL shortener with a few additional tricks. To support all the features we wanted to provide our uses, we decided to go with a full Ruby on Rails application. We were worried about expensive scaling with Rails, if the service ever really caught on.
But there was really no need to scale most of the application. The admin interface would not be used heavily, and usage would likely grow predictably. The only element on the application that might grow quickly and demanded high scalability was the actual URL redirection – that is, turning our shortened URLs into long URLs.
So we decided to separate our this piece of the application and build a separate web service. URLs are created and served from a very lightweight Sinta application which is under 100 lines of code. This application is hosted on a cloud based web service that can be instantly scaled depending on usage. The Rails application queries the Sinatra application to create URLs and to read URL statistics. This is done via RESTful web service.
An additional benefit of this method is we get a working API for integration with other services as well. We’ve already implemented this on Contribune, a social news site. Posting a story automatically creates a Giv.to URL for each posting.