Upgrade to Pro — share decks privately, control downloads, hide ads and more …

15 years with Rails and DDD

15 years with Rails and DDD

The problem with big Rails apps is that it's one big model all ActiveRecords together with service objects.
There are no clear boundaries.

This talk presents a solution based on DDD - create many models - domain models and read models.

Avatar for Andrzej Krzywda

Andrzej Krzywda

June 16, 2025
Tweet

More Decks by Andrzej Krzywda

Other Decks in Programming

Transcript

  1. Andrzej Krzywda, Chicago Ruby User Group, 2025 15 years with

    Rails and DDD Lessons learnt [ahn-jay]
  2. Bene fi ts • AR for UI, queries, forms, json

    • Service objects - well-named • Service objects - one place • Simplicity of CRUD • Business-e ff ective The Rails Way architecture
  3. • Big classes (User, Order, Product) - over 50 columns

    • No modularization (microservices don't help either) • Hard to unit test • Service objects rules • Coupling • Cohesion • Tracking Callbacks • Deadlocks in transactions • Slow reports (multiple joins) • Not junior friendly • Not AI friendly Problems in bigger Rails apps
  4. • Maps business into code • Model per domain •

    Shared language • Modelling process • Strategical DDD • Tactical patterns - repository, value object, entity and many others DDD
  5. problems • overkill for small apps • risk of over-engineering

    • boilerplate code • devs focus on tactical patterns DDD
  6. • No new inventions • Keep what's great in Rails

    • Keep what's great in DDD • Allow CRUD domains • Allow rich domains • Junior-friendly • AI-friendly The Dream Rails Architecture What
  7. App Domain Admin panel Public app Mobile API Shopify GraphQL

    Service Objects Controllers AllProducts Ledger AllOrders Month Report Read models webhooks ImportOrderService SupplyProductService SubmitOrderService O ff er Cart Public::OrdersController Admin::ProductsController Writes Reads Public::CartController commands
  8. App Domain Admin panel Public app Mobile API Shopify GraphQL

    Domains Pricing Inventory Catalog Shipping Invoicing Ordering Events Commands
  9. App Domain Admin panel Public app Mobile API Shopify GraphQL

    Service Objects Controllers Domains Pricing Inventory Catalog Shipping Invoicing Ordering AllProducts Ledger AllOrders Month Report Read models Events Commands SupplyProductService Admin::ProductsController Writes Reads Process Managers
  10. App Domain Admin panel Public app Mobile API Shopify GraphQL

    Service Objects Controllers Domains Pricing Inventory Catalog Shipping Invoicing Ordering AllProducts Ledger AllOrders Month Report Read models webhooks ImportOrderService Events Commands SupplyProductService SubmitOrderService O ff er Cart Public::OrdersController Admin::ProductsController Writes Reads Public::CartController Process Managers
  11. App Domain Admin panel Public app Mobile API Shopify GraphQL

    Service Objects Controllers Domains Pricing Inventory Catalog Shipping Invoicing Ordering AllProducts Ledger AllOrders Month Report Read models webhooks ImportOrderService Form objects Events Commands SupplyProductService SubmitOrderService O ff er Cart Public::OrdersController Admin::ProductsController Writes Reads Public::CartController Process Managers