---
title: "Scaling Rails Series"
description: "Scaling Rails"
canonical_url: "https://www.bigbinary.com/blog/scaling-rails-series"
markdown_url: "https://www.bigbinary.com/blog/scaling-rails-series.md"
---

# Scaling Rails Series

Scaling Rails

- Author: Vishnu M
- Published: April 22, 2025
- Categories: Rails, Puma

Rails makes it pretty easy to get started with development. You don't even have
to set up your database. It comes with SQLite. Install Rails, and you start the
development.

Same with deploying to production. You need to change your database. Other than
that it comes with sane defaults. You don't really need to know what's
`RAILS_MAX_THREADS` and what's `WEB_CONCURRENCY`. However, as your application
starts getting more traffic, you want to scale your application.

Over the last 13 years of consultancy at BigBinary, we have seen all types of
applications.

We have seen Rails applications which are IO heavy like scraping websites. There
are applications which are heavy on background jobs. Then there are flash sale
sites where there is no traffic one minute and the next minute there are tons of
traffic. Then there are ticketing sites.

Each application has its own challenges.

If an application is not properly tuned, then we can run into all kinds of
issues. You can run out of memory or database connections. In some cases,
because of the wrong configuration, Sidekiq jobs were failing and these jobs
continued to get enqueued which made the situation worse.

To solve all these types of issues, we need to know what's actually happening.
And that's what we will do. We will look at under the hood to see how Rails
works, how Puma works, how connection pooling works, how to tune Sidekiq and how
to measure what we need to know to make decisions.

It's a journey to understand from the ground up how to scale Rails applications.
This page will have links to all the future blogs. You can follow the Scaling
Rails series by joining the newsletter or following us on
[twitter](https://twitter.com/bigbinary) or
[LinkedIn](https://www.linkedin.com/company/bigbinary/). We even have an
[RSS feed](https://bigbinary.com/blog/feed.xml).

### [Part 1 - Understanding how Puma handles requests](https://www.bigbinary.com/blog/understanding-puma-concurrency-and-the-effect-of-the-gvl-on-performance)

- How Puma handles requests
- Default Puma configuration in a new Rails application

### [Part 2 - GVL in Ruby and the impact of GVL in scaling Rails applications](https://www.bigbinary.com/blog/gvl-in-ruby-and-its-impact-in-scaling-rails-applications)

- Web applications and CPU usage
- CPU bound or IO bound
- Concurrency vs Parallelism
- Understanding the GVL
- GVL dictates how many processes you will need
- Thread switching
- Visualizing the effect of the GVL

### [Part 3 - Amdahl's Law: The Theoretical Relationship Between Speedup and Concurrency](https://www.bigbinary.com/blog/amdahls-law-the-theoretical-relationship-between-speedup-and-concurrency)

- Amdahl's law
- Relationship between speedup gained and the number of threads
- Ideal number of threads in a process
- Request queue time

### [Part 4 - Finding ideal number of threads per process using GVL Instrumentation](https://www.bigbinary.com/blog/tuning-puma-max-threads-configuration-with-gvl-instrumentation)

- GVL instrumentation using perfm
- Determining the I/O workload of an application using the GVL data
- Empirically determining the ideal number of Puma threads for an application

### [Part 5 - Understanding Active Record Connection Pooling](https://www.bigbinary.com/blog/understanding-active-record-connection-pooling)

- Database connection pooling
- Active Record connection pool implementation
- Connection pool configuration options
- Active Record connection pool reaper
- How many database connections will the web and background processes utilize at
  maximum?
- How does using `load_async` affect the connection usage?
- Setting database pool size configuration
- PgBouncer
- Tracking down `ActiveRecord::ConnectionTimeoutError`
- Monitoring Active Record connection pool stats

### [Part 6 - Understanding Queueing Theory](https://www.bigbinary.com/blog/understanding-queueing-theory)

- Queueing systems
- Basic terminology in queueing theory
- Little's law
- The knee curve
- Theoretical parallelism
- Concurrency and effective parallelism

## Links

- [Human page](https://www.bigbinary.com/blog/scaling-rails-series)
