Chapter 15. Scaling Gracefully

Scaling has always been a controversial issue for Rails applications, yet there are many examples of apps that have been able to scale successfully. The key is always being able to identify bottlenecks and distribute the load across different services to handle different tasks efficiently. In this chapter, we are going to see how we can break down the complex task of scaling an application, and how this doesn’t simply mean scaling a specific framework (in this case, Rails). We are going to introduce the concept of middleware and see how we can use it to distribute the load across the different server instances and APIs that we are going to use, in order to scale horizontally. We will take a look at Nginx and the Lua programming language to see how these can be used to create a front-facing HTTP server and load balancer for our APIs.

Scaling Rails

As mentioned, scaling is a controversial issue in Rails. But let’s tackle this issue with the appropriate preparation.

First of all, there are a couple of concepts about scaling that we should have clear. Scaling a service isn’t just about the framework used to code the service functions. It is about the architecture, the databases, how you use caching, how events are queued, disk I/O, content distribution networks, and a variety of other things.

So to answer the question “Does Rails scale?” as straightforwardly as possible, the response is definitely “Yes!”

Furthermore, to comment on that question, Rails ...

Get RESTful Rails Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.