Advanced Concepts in Ruby on Rails Hosting Part I
Let us imagine how a translation company starts out, lets call this company MOG Translation, Inc. At first, there might be one translator and one manager. The manager receives a document from a client and hands it to his translator. The translator might turn around the document in 1 hour, making its way back to the manager and then customer's hands. That is also the fundamentals behind hosting a website. In the most simple form, a web server acts like the manager: it takes in a request (http://mog.com/ for example) and hands it to the application server. The application server acts like a translator, it receives the request and turns it into HTML code that is passed back to the web server and shows up in your web browser.
Soon, MOG Translation, Inc. gets a good reputation and the translation documents come in faster than one per hour. Suddenly our poor lonely translator can't keep up and the papers keep piling up. We all know what to do: hire more translators. Now MOG Translation, Inc. has 10 translators on staff and the manager gets to pick how to hand out the work. One of the simplest ways to hand out documents is to pass them out one at a time to each translator. "One document for Nancy, One document for Drew ...", then when you get to the end of the line go back and starting handing out to Nancy again. Whenever the translators finish, they hand the translation back to the manager who makes sure it goes to the right client. In computer lingo, this system is called round-robin. You have one web server that distributes requests to 10 application servers in a round-robin way.
MOG Translation, Inc. gets such a good reputation that 10 translators is simply not enough. Unfortunately, the office is already a bit cramped so it is time for MOG to open a new branch, another office with another 10 translators. This is equivalent to adding a new server to handle more load. In order to make this change invisible to the customer, we do not want to change the face of our company, so the manager stays the same. But now when he gets to the end of the line in office 1, he faxes the next documents directly to the desks of the translators at office 2. This system is still round-robin, and works fine when adding even more offices.
This is the standard way that many web site's infrastructures grow. In order to handle more requests, they get more servers with more instances of the application running to handle more people visiting the site. The vast majority of web sites never need to grow beyond this point, however popular ones like MOG do. Imagine a talented manager who sends requests to three offices with 10 people in each office in a round-robin way. Problems arise because some documents are longer than others, and some translators are faster than others. This leads to congestion where even though the manager is handing the documents out evenly, some translators desks build up piles. When a pile builds up, even if a very easy document comes in, it might take a lot longer due to the other documents before it. Sure, you could just get more translators, but can you think of a better way to utilize the resources you already have?
Next week I will tell you what I did to better utilize our resources. For the more technical of my readers, the "manager" web server software we use is nginx, a very fast reverse proxy from Russia and the "translator" application software is mongrel which renders Ruby on Rails. Using a reverse proxy and mongrel is the canonical way to serve Rails web sites.
Technoblog reader special: $10 off web hosting by FatCow!

6 Comments:
Great explanation can't wait until part two!
3:59 PM, June 19, 2007
where is the advanced part?
10:07 AM, June 20, 2007
The advanced part is coming next week.
10:25 AM, June 20, 2007
Hey, welcome back to the blogosphere! :)
10:58 AM, June 30, 2007
i don't think you are using the word canonical correctly.... I presume you mean the simplest way of expressing a concept that still retains the concept therefore
the canonical way of servings rails websites is webrick. Your way is probably a best practice for scalable rails sites....
10:24 PM, July 08, 2007
canonical--
Princeton: conforming to orthodox or recognized rules
Wikipedia: It essentially means "standard", "generally accepted" ...
I hate when people who have a grudge with me (there is only one person on earth that meets this standard: Benjamin Grant), decide to try to belittle me with inane, bordering on non sequitur comments like this. Next time, Ben, at least make sure you fact check your rebuttals to my blog posts. That way I can just delete them.
11:54 PM, July 08, 2007
Post a Comment
<< Home