You use Rails every day.
But do you know how it actually works?

This book takes you inside the Rails source code — not to teach you how to use Rails, but to show you how Rails uses Ruby.

10 chapters · 40,000 words · 300 pages · Rails 8.1

Get the Book PDF + EPUB · Instant download
Rails Under the Hood book cover

You'll trace a request from rails server to rendered HTML. You'll see how ActiveRecord builds SQL through an abstract syntax tree. You'll discover that Rails routing is powered by a finite automaton straight out of a computer science textbook.

10 chapters of Rails internals

Every explanation includes real code snippets with file paths so you can explore the source yourself.

Chapter 01

The Boot Process

60+ initializers, topologically sorted, running in under 2 seconds

Chapter 02

The Request Lifecycle

Every layer between Rack and your controller action

Chapter 03

Routing Internals

How resources :posts compiles into a finite automaton

Chapter 04

ActiveRecord

Arel, lazy evaluation, connection pooling, the visitor pattern

Chapter 05

Autoloading & Zeitwerk

Why const_missing was replaced and how Module#autoload works

Chapter 06

The Middleware Stack

25 layers you never see but depend on every request

Chapter 07

Security Internals

CSRF one-time-pad masking, SafeBuffer, encrypted credentials

Chapter 08

ActiveJob

The adapter pattern, GlobalID serialization, polynomial backoff

Chapter 09

Action Cable

Pub/sub architecture, WebSocket lifecycle, the reactor pattern

Chapter 10

Caching & Performance

Cache stores, Russian doll caching, HTTP ETags, query cache LRU

Built for experienced Rails developers

This is not a beginner tutorial. It's the book you read after you've shipped Rails apps and want to understand why they work.

This book is for you if:

  • You've used Rails for 2+ years and want to go deeper
  • You debug framework issues by reading stack traces, not Stack Overflow
  • You want to understand why Rails works, not just how to use it
  • You're preparing for senior/staff-level roles

This book is NOT for you if:

  • You're learning Rails for the first time
  • You want a step-by-step tutorial
  • You prefer high-level overviews over source code

Real source, real file paths

Every chapter traces through actual Rails code. No pseudocode. No hand-waving.

# railties/lib/rails/engine.rb, line 692
def build_middleware_stack
  config.middleware.build(endpoint)
end

# actionpack/lib/action_dispatch/middleware/stack.rb
def build(app = Proc.new)
  middlewares.reverse.inject(app) do |a, e|
    e.build(a)
  end
end

# The entire middleware stack is built with
# reverse.inject — each middleware wraps the next.
# This is why order matters. This is why
# the last middleware added runs first.

From Chapter 6: The Middleware Stack

Stop guessing.
Start reading the source.

300 pages of Rails internals, explained by someone who read every line so you don't have to.

Get Rails Under the Hood

PDF + EPUB · Instant download · Free updates