Understanding Rails · Season 1: The trip of one click
The front door
Episode 2 · overview · about 2 minutes · Rails 8.1 · by Tommy A. Caruso
How was this episode?
The series' author reads every note, and no one else sees it. When something is wrong or unclear, it gets fixed and the episode re-cut. How this series stays right.
Not endorsed yet. Are you a Rails developer? What's an endorsement?
Endorse this version To endorse: create an account, confirm your email, then link GitHub.
What changed
- Version 3, November 20, 2026: A review against Rails 8.1 found Thruster runs only in production, so the narration now says so.
- Version 2, November 20, 2026: Added Propshaft::Server to the list of middleware on screen, which left it out.
Thruster, Puma, the env hash, Rack, and the middleware stack.
Free to watch. If it helped, support the series.
Transcript
0:00 The front door
Part two. The front door.
Our request has reached the server. But it doesn't hit Rails straight away. First it passes a couple of doormen.
0:14 Thruster
In production, the first is Thruster, which comes with every new Rails 8 app. Thruster handles the jobs that don't need Ruby at all. It compresses responses, caches files like images and stylesheets, and speaks modern HTTP to the browser.
0:32 Puma
Behind it stands Puma, the app server. Puma is what actually runs your Ruby code. It keeps a few threads ready, so several requests can be handled at the same time.
0:43 The env
Puma's real job is translation. It reads the raw HTTP text, and turns it into a plain Ruby hash called the env. The verb, the path, the headers, the body: all in one hash.
0:57 Rack
Then Puma hands that hash to Rack. Rack is a tiny agreement that Ruby web frameworks follow. An app is anything with a method named call. It takes the env, and returns three things: a status, the headers, and a body.
Sound familiar? Those are the three parts of an HTTP response. Rack is HTTP, written in Ruby.
1:21 Middleware
Rails doesn't answer right away, either. First, the env travels through a stack of middleware. Each one is a small Rack app wrapped around the next. It sees the request on the way in, and the response on the way out.
A new Rails app has more than twenty of them. To see yours, run bin slash rails middleware.
Three of them matter for our click. Method override lets a plain form act like it sent patch or delete. Cookies unpacks the cookie, ready for Rails to check who you are. And show exceptions turns a crash into a proper error page.
At the bottom of the stack sits the last stop: the router. That's where Rails itself begins, and where part three picks up.
Check your understanding
-
You write a tiny Rack app. What must its call method return?
- A string of HTML
- The env hash, with the response added
- An array of three things: a status, the headers, and a body
- A Rails controller
Show answer
An array of three things: a status, the headers, and a body. Rack's rule is that call returns exactly three things. Those are the same three parts as an HTTP response. Source: A Basic Rack Application, Rails on Rack (Rails Guides 8.1).
-
Browsers can only send GET and POST from a plain form. Which middleware lets that form act like it sent DELETE?
- ActionDispatch::Cookies
- Rack::MethodOverride
- ActionDispatch::ShowExceptions
- ActionDispatch::Static
Show answer
Rack::MethodOverride. Rack::MethodOverride changes the method when the form sends a hidden _method field. That is how Rails supports PATCH and DELETE. Source: Rack::MethodOverride, Rails on Rack (Rails Guides 8.1).
-
Three requests reach Puma at the same moment. How can it handle them together?
- Each request gets a thread from Puma's pool of threads
- Thruster runs the Ruby code for two of them
- Rack holds two of them until the first is done
- Rails starts a new server for each one
Show answer
Each request gets a thread from Puma's pool of threads. Puma serves each request in a thread from a pool it keeps ready. A new app starts with 3 threads. Source: The new app's config/puma.rb template (Rails source, v8.1.4.1).
-
Thruster sits in front of Puma. Which job does it take off Puma's hands?
- Running your controllers
- Matching the request to a route
- Caching and compressing files like images and stylesheets
- Checking the authenticity token
Show answer
Caching and compressing files like images and stylesheets. Thruster handles work that needs no Ruby, like asset caching and compression. Puma still runs your app's code. Source: Thruster, Ruby on Rails 8.0 Release Notes (Rails Guides 8.1).
Sources
- Thruster README (Thruster v0.1.28)
- A Basic Rack Application, Rails on Rack (Rails Guides 8.1)
- Inspecting the Middleware Stack, Rails on Rack (Rails Guides 8.1)
- Rack::MethodOverride, Rails on Rack (Rails Guides 8.1)
- Thruster, Ruby on Rails 8.0 Release Notes (Rails Guides 8.1)
- The new app's config/puma.rb template (Rails source, v8.1.4.1)