Rails Scales!
Practical Techniques for Performance and Growth
by Cristian Planas
Rails doesn’t scale. So say the naysayers. They’re wrong. Ruby on Rails
runs some of the biggest sites in the world, impacting the lives of
millions of users while efficiently crunching petabytes of data. This
book reveals how they do it, and how you can apply the same techniques
to your applications. Optimize everything necessary to make an
application function at scale: monitoring, product design, Ruby code,
software architecture, database access, caching, and more. Even if your
app may never have millions of users, you reduce the costs of hosting
and maintaining it.
Optimize every aspect of your Ruby on Rails applications for world-class
performance. Tweak your Rails app for snappy responsiveness. Find
bottlenecks that slow your code. Scale an app for massive data sets.
This book introduces techniques, patterns, and tricks to make your Rails
application become more performant and scale to billions of requests per
day. And it does it in an entertaining and fun way, sharing real-life
stories of all kinds: tales from the trenches of working on massive
Rails apps, and anecdotes from working on much smaller projects in tiny
organizations of a handful of engineers. Through all these experiences
you will learn that scaling Rails applications is a multifaceted task,
including aspects such as monitoring, query tuning, and memory-aware
coding.
This book is for programmers of all levels of experience, from beginners
to experienced Rails veterans. You can even show your nontechnical
colleagues the features and limitations of Rails at scale.
Reading this book will help you make Rails applications that fly. And it
will make you enjoy the process.
What You Need
In the course of this book we will be using Rails 8.0 and Ruby 3.4. The
data stores used will be MySQL, Postgres, Redis, and Memcached.
Resources
Releases:
2025/06/04
P1.0
First printing.
2025/04/22
B8.0
Production is complete. Now it’s on to layout and the printer.
2025/03/07
B7.0
The book is content-complete and headed to production.
2025/02/13
B6.0
*Completed the chapter “Monitoring Performance to Build Scalable Systems”.
*Completed the epilogue.
*Book completed.
*Minor adjustments in most of chapters after second review.
- Introduction
- We Need to Talk About the Rails Learning Curve
- Techniques for a Rails Renaissance
- About This Book
- Setting Up Your Machine
- Understanding the Application Database Setup
- Downloading the Application
- Setting Up Ruby
- Installing the Database(s) and the Caching Stores
- Setting Up Rails
- Loading the Example Dataset
- Summing Up
- Optimizing Data Access with ActiveRecord
excerpt
- Managing Data the Rails Way
- Removing n+1s and Preloading Data
- Discovering Wide Fetching and Narrow Fetching
- Explaining EXPLAIN
- Indexing
- Summing Up
- Understanding All the Faces of Caching
- Caching and Denormalizing
- Using counter_cache in Rails
- Setting Up Your Caching
- Using Fragment Caching
- Using Russian Doll Caching
- Writing Your Own Caching
- Using Write-Through Caching
excerpt

- Implementing Fan-Out Writing
- Using Action Caching and Page Caching
- Adding a Cache Layer to ActiveRecord
- Choosing a Storage System for Your Cache
- Using Denormalization
- Summing Up
- Designing a Scalable API
- Paginating Your Endpoints
- Discovering Cursor-Based Pagination
- Splitting Your Model Data
- Implementing Sideloads
- Using GraphQL
- Summing Up
- Tracking the Lifecycle of a Request
- Crossing the Internet with One Request
- Using HTTP Headers to Speed Up Your Application
- Introducing CDNs
- Summing Up
- Thinking Architecture for Performance
- Discovering Sharding.
excerpt

- Improving Your Response Time with Asynchronous Processing
excerpt

- Getting Started with Event-Driven Microservice Architectures
- Summing Up
- Designing Product for Performance
- Setting Product Limits
- Managing the Life of Your Data
- Doing Things That Don’t Scale
- Increasing Your Usability Time
- Summing Up
- Monitoring Performance to Build Scalable Systems
excerpt
- Choosing and Installing Your Observability Platform
- Monitoring (Almost) All the Things!
- Building Your Own Dashboards
- Setting Up Performance Error Budgets
- Being Wary of How Much You Spend
- Summing Up
- Scaling, Beyond Performance
- Setting Up Ownership for Your Application
- Modularizing Your Application
- Using Feature Flags for Better Rollouts
- Summing Up
- The Next 20 Years with Rails
- Scaling with Human-First Technology
Author
Cristian Planas has worked with Ruby on Rails for more than 15
years. He has used Rails in wildly different situations, ranging from
being the CTO of a start-up, to creating an application for small NGOs,
to serving as Group Tech Lead at Zendesk, improving the performance of
one of the biggest Rails monoliths in the world.