Skip to content
RY

Rails Architecture, Start to Finish: Every Component and the Exact Boot Timeline

Ram Laxman Yadav10 min read

Most Rails developers can tell you what a model, a controller, and a migration are. Far fewer could tell you, in order, what actually happens between running bin/rails server and your app being ready to answer a request — or which of the dozen-odd gems under the rails umbrella is actually responsible for which piece of that. This post is both: a component-by-component map of how Rails is put together, and the literal, in-order sequence of events that gets you from a cold terminal to a running server — grounded in Rails 8.1, the version actually shipping today.

1. The component map: what’s really inside “Rails”

“Rails” isn’t one gem — it’s a thin umbrella (rails.gemspec) that pins a specific version of roughly a dozen independently-versioned libraries, each with its own job. The diagram below reads top to bottom as “depends on”: everything in a row sits on top of, and depends on, everything in the row beneath it.

Railties — registers every layer below with a booting app

Self-contained engines

Action MailerActive JobAction CableActive StorageAction TextAction Mailbox

Request / response (Action Pack)

Action DispatchAction ControllerAction View

Shape of data

Active ModelActive Record

Foundation

Active Support

A quick tour of each row, bottom to top:

Active Support — the bottom of the stack, and the one true dependency everything else shares. Core-class extensions (3.days.ago, "foo".camelize), ActiveSupport::Concern, time zone handling, caching primitives, and ActiveSupport::Notifications (the instrumentation bus almost every other component publishes events onto). It depends on nothing else in this diagram.

Active Model / Active Record — Active Model is validations, callbacks, attribute type casting, and the interface (ActiveModel::API) that lets a plain Ruby object behave like a model in forms and views without touching a database. Active Record is Active Model plus persistence: connection adapters, the query interface, migrations, associations. This is the one most people mean when they say “the model layer” — but it’s built on top of Active Model, not the other way around.

Action Dispatch / Action Controller / Action View — collectively “Action Pack.” Action Dispatch is the router and middleware stack (cookie handling, session management, flash). Action Controller is the base class your controllers inherit from. Action View is template rendering — a genuinely separate library, which is why API-only Rails apps can drop it entirely.

The self-contained engines — each one its own Rails::Engine, each solving one job end to end: outbound email (Action Mailer), a queuing abstraction that hands real work off to an adapter (Active Job), WebSockets (Action Cable), file uploads and variants (Active Storage), rich text built on Active Storage and Trix (Action Text), and inbound email routing (Action Mailbox).

Railties, wrapping the whole diagram — every component above is implemented as a Rails::Railtie (or the Rails::Engine variant, for anything shipping its own routes/views/migrations). A Railtie is how a library registers initializers, rake tasks, and generators with a booting Rails app without that app needing advance knowledge of it. Third-party gems use exactly this mechanism — a gem with lib/my_gem/railtie.rb is doing precisely what active_record/railtie.rb does internally.

Note

The practical consequence of this layering: an API-only Rails app isn’t “a smaller version of Rails,” it’s an app that simply never loads Action View, Action Mailer, or Action Cable’s railties in the first place. Nothing is disabled — it’s just never required, and Active Support/Action Dispatch/Action Controller/Active Record do the entire job on their own.

2. The boot timeline: from bin/rails server to your first request

This is the part almost nobody walks through end to end. Below is the actual, in-order sequence for Rails 8.1 — a couple of class names here (Rails::Server < Rackup::Server, rather than the older Rack::Server) are specific to recent Rails versions, so don’t be surprised if this looks slightly different from a five-year-old blog post on the same topic.

1

bin/rails

Computes APP_PATH (pointing at config/application, relative to itself), requires config/boot.rb, then requires rails/commands.

2

config/boot.rb

Sets ENV["BUNDLE_GEMFILE"] if unset, calls require "bundler/setup" — this only makes Gemfile gems available to require, it does not require them yet — then requires bootsnap/setup to cache expensive boot work.

3

rails/commands

Expands short aliases (s → server, c → console, r → runner), then Rails::Command.invoke dispatches to the matching command class, or falls through to Rake if nothing matches.

4

ServerCommand#perform

Creates tmp/cache, tmp/pids, and tmp/sockets, builds a Rails::Server instance, then requires APP_PATH — loading config/application.rb for the first time.

5

config/application.rb

Requires "rails/all", loading every framework’s Railtie/Engine (each wrapped in its own rescue LoadError). Immediately after, Bundler.require(*Rails.groups) runs — this is the line that actually requires every gem in your Gemfile. Only then is your Rails::Application subclass defined.

6

Rails::Server#start

Traps INT (so Ctrl-C exits cleanly), applies --dev-caching if passed, and calls super into Rackup::Server#start.

7

Rackup::Server#start

Memoizing @wrapped_app is what actually triggers config.ru to be parsed, before any daemonizing happens — then daemonize_app and write_pid run if configured.

8

config.ru → config/environment.rb

config.ru requires config/environment.rb, which calls Rails.application.initialize! — the single call that kicks off everything else.

9

run_initializers

Every registered initializer is topologically sorted and run in three phases: bootstrap (logger, etc.) first, then railtie initializers — load_environment_config reads config/environments/<env>.rb, load_config_initializers loads config/initializers/* alphabetically, add_routing_paths loads config/routes.rb — then finisher initializers, which build the middleware stack.

10

Rack::Builder

build_app wraps your now-fully-initialized Rails application in the middleware stack assembled in the previous step — session handling, cookie parsing, and anything your app or its gems registered.

11

Rack::Handler::Puma.run

Builds a Puma::Launcher and starts it listening. Your app is now serving requests.

Where autoloading and eager loading fit into this: Rails sets up Zeitwerk loaders during the initializer phase, not before. In development, config.eager_load is false by default — constants are autoloaded lazily, the first time they’re referenced, which is why a typo in a rarely-used class can go unnoticed until something finally touches it. In production, config.eager_load is true, and Zeitwerk walks every autoload path and requires everything up front during boot — slower to start, but it means a broken constant reference surfaces immediately at deploy time instead of the first time a real user hits that code path.

Warning

One genuinely common mistake this timeline explains: trying to reference an app-level model or service class directly inside a file in config/initializers/. Initializers run once, during boot, before your app’s autoload paths are set up the way they are for a normal request — reloadable constants referenced there can end up stale or unavailable. The documented fix is to defer that reference into a config.to_prepare or config.after_initialize block instead, both of which run after the app’s own autoloading is actually ready.

3. The components actually running underneath a modern Rails app

A Rails app generated today looks meaningfully different under the hood from one generated even three or four years ago — not in the MVC layer, but in what’s doing the work behind Active Job, Action Cable, and Rails.cache, and in how it gets deployed. The throughline across almost all of it: fewer external services a small-to-medium Rails app is required to run just to get started.

Puma + Thruster

Puma is still the default app server — same as since Rails 5 — but Thruster now sits in front of it by default, handling X-Sendfile acceleration, asset caching, and compression so Puma doesn’t have to.

Propshaft

The default asset pipeline, replacing Sprockets. It deliberately does far less — no built-in bundling or transpiling — on the premise that modern browsers and HTTP/2 made most of that unnecessary.

The Solid trio

Solid Queue (Active Job), Solid Cache (Rails.cache), and Solid Cable (Action Cable) are all database-backed by default now — no separate Redis or Sidekiq required for a large share of apps.

Kamal

The default deployment tool a new app is wired up for — deploying a containerized app directly to your own server(s), rather than assuming a managed platform-as-a-service.

Hotwire + importmap

Turbo and Stimulus are the default frontend approach, paired with importmap-rails to serve JavaScript with no Node.js build step at all, for apps that don’t need a full SPA framework.

Zeitwerk + bootsnap

Covered in section 2 — one for how constants get found at all, the other for keeping repeated boots fast during development.

Where a 2019-era Rails app’s production checklist usually included “stand up Redis” on day one, a Rails 8.1 app’s does not — Active Job, Action Cable, and Rails.cache all have a working, database-backed default out of the box, with Redis still available as a drop-in swap later if you outgrow it.

Get new posts in your inbox

One email whenever I publish something new. No spam, unsubscribe anytime.

← Back to all posts