Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

The Modular Monolith in Rails: Engines, Packwerk and Boundaries

The article explores building modular monoliths in Rails using tools like Engines, Packwerk, and explicit boundaries to organize code into distinct modules within a single application, aiming to improve maintainability and avoid the complexity of microservices while keeping deployment simple.

Background

- The "modular monolith" is a middle ground between a single Rails app and microservices: you keep one deployable unit but enforce strict code boundaries so different parts (e.g. Orders vs Payments) cannot accidentally depend on each other's internals. - **Ruby on Rails** is a popular web framework. A "monolith" means all code lives in one app — simple to deploy but prone to tangled spaghetti code as it grows. - **Engines** are a built-in Rails feature for packaging sub-apps (models, controllers, views) into semi-independent modules, like plug-ins. - **Packwerk** is an open-source Ruby gem from Shopify that enforces dependency rules at the code level — e.g. it prevents the Orders package from calling a private method in Payments. - The post compares these three approaches for enforcing boundaries, noting tradeoffs in complexity, strictness, and ease of future extraction into separate services.

Related stories