devto 2026-06-25 원문 보기 ↗
A Rails app grows. Changes in one corner start breaking another, two teams keep colliding in the same files, and eventually someone says the word microservices.
Almost always, that's the wrong instinct. What you usually need is a modular monolith: one deployable Rails app, with real, enforced boundaries between its parts. The interesting contrast isn't monolith versus microservices — it's an organised codebase versus a big ball of mud.
This is the current, Rails 8 / Zeitwerk-era version of how I think about it. No nostalgia, no hype.
Reach for a modular monolith when:
If none of that is true yet, skip to the "when NOT to" section before you do anything.
There are three honest ways to draw boundaries inside a Rails app, plus the network boundary you get from microservices. They are not interchangeable.
| Dimension | Rails Engines | Packwerk | Namespaced modules | Microservices |
|---|---|---|---|---|
| Boundary enforced by | App structure + loader | Static CI analysis | Convention / review | The network |
| Setup overhead | Medium | Low | Lowest | Highest |
| Runtime isolation | Partial | None | None | Total |
| Best when | You want hard boundaries and a clean extraction path | Large existing app you can't restructure today | Early, small app | You have a genuine scaling or isolation need |
The short version: Packwerk meets your monolith where it already is — you add it to a sprawling app and let CI tell you where the boundaries leak, without moving a single file first. Engines give you the strongest structural boundary and the cleanest path to one day lifting a slice out. Plain namespaced modules cost almost nothing and are often the right first step. Microservices buy you total isolation and charge you an operational tax for it — only worth paying when the isolation is the actual requirement.
Zeitwerk maps constants to file paths, and it's unforgiving on purpose: billing/ledger.rb must define Billing::Ledger. A few things follow from that:
Zeitwerk::NameError, that's the boundary working, not the framework being difficultThat last point catches a lot of people who assume an engine is a sealed box. It isn't.
You don't get to stop the world and rearchitect. So the move is small, reversible steps, each with a safe stopping point:
The point of "ship" after every step is that you can stop after any of them and still have a working, revenue-generating app. No big-bang branch that lives for three months.
This is the section most articles skip, so I'll be blunt. Don't modularise when:
And a Rails 8 note: Solid Queue, Solid Cache and Solid Cable have quietly removed a lot of the old pressure to extract services just to get a queue or a cache. The case for a well-organised monolith is stronger now than it was in 2018.
Is a modular monolith just a step towards microservices? Sometimes, but treating it as merely a stepping stone is the wrong frame. For a lot of teams it's the destination — you get most of the organisational benefit without the operational bill.
Engines or Packwerk first? If you have a large existing app you can't restructure this quarter, Packwerk first — it tells you where the boundaries actually are. If you're starting a new bounded area cleanly, an engine.
Does Zeitwerk enforce my boundaries? No. It enforces naming. Boundaries are enforced by you and your CI.
The original, kept up to date, is here: https://davidslv.uk/modular-monolith-rails/
If you want to go deeper, I wrote a free book on exactly this — Modular Rails: Architecture for the Long Game, all 18 chapters free to read online: https://davidslv.uk/books/modular-rails/ . There are runnable companion repos in it (Orbit, a worked example; and a small tool for finding seams). No sign-up wall.