What is Thin and why do I need it

Solution 1:

Thin, or Passenger, or WEBrick, or any other such web server, has a single purpose. It takes an HTTP request from the network and passes it up to Rack, and returns the application's response onto the network.

(Typically, Rack is used as one component of a complete Ruby application written with a framework such as Rails or Sinatra. It processes incoming HTTP requests via its own middleware and ensures that they get routed to the correct application code.)

What happens to the request after Thin sends it to Rack is generally not Thin's concern; it's the concern of the application and the application developer.

The reason that a Ruby web server is typically placed behind a more traditional web server such as Apache or nginx is for performance. The Ruby web server is written in Ruby and optimized to deal with the application stack that it is serving. In particular, it is not necessarily very good at serving static assets quickly. In the usual production setup, a traditional web server will serve the static assets, which Rails precompiles either as a rake task during deployment or on first access, and Thin (or your server of choice) will pass along everything else to the application. As a result, running Thin alone is useful only in a development environment, since performance there is generally not an issue. It is not something we would do. (And usually WEBrick is used for that purpose, as it's the default web server for Rails applications.)

As system administrators, we generally don't care about the application code, though in some cases you will want to work with the developer to evaluate which of several possible Ruby web servers should be used with a given application. Though as a general rule, from the perspective of the application they should be interchangeable.