Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Capstone: Extraction-Ready Modular Monolith for Orders

Track

Architecture-only

Brief

A four-person team is rebuilding an order system that must ship as one deployable application this year, although order processing may become an independent service after the domain stabilizes. The existing codebase shares repositories and domain objects among checkout, inventory, billing, and shipping, making every change cross-cutting. Leadership wants strict boundaries without paying for a broker, service discovery, or multiple deployment pipelines yet. Design a modular monolith that keeps today’s operations simple and leaves a credible extraction path.

Constraints

  • One team of four owns the entire system, with one deployment pipeline and one on-call rotation.
  • The existing stack is a JVM web framework and PostgreSQL; adding a message broker is out of scope.
  • Checkout writes must complete within 500 ms at p95 under normal load and cannot depend on remote calls.
  • Checkout, inventory, billing, and shipping need explicit public APIs and separately owned persistence.
  • Architecture checks must reject cross-module repository imports and domain dependencies on web or database frameworks.

Required Patterns

  • Modular Monolith — WHY: one deployment preserves the small team’s operational simplicity while enforced module APIs and data ownership create future service boundaries.
  • Hexagonal Architecture — WHY: ports keep order use cases independent of payment, inventory, HTTP, and PostgreSQL adapters that may change during extraction.
  • Layered Architecture — WHY: interface, application, domain, and infrastructure responsibilities remain visible inside each module without creating horizontal layers shared by every module.

Solution Sketch

Illustrative pseudocode and configuration — not runnable.

deployment: orders-monolith (one artifact, one PostgreSQL cluster)

module checkout:
  interface:    CheckoutController -> PlaceOrderHandler
  application:  PlaceOrderHandler -> InventoryPort, PaymentPort, OrderRepositoryPort
  domain:       Order, OrderLine, Money; imports no framework or other module
  infrastructure: PostgresOrderRepository implements OrderRepositoryPort
  owns:         checkout_schema.orders, checkout_schema.outbox
  exposes:      CheckoutApi.placeOrder(), CheckoutApi.orderStatus()

module inventory:
  exposes:      InventoryApi.reserve(lines)     # in-process public API today
  owns:         inventory_schema.reservations
  forbidden:    import checkout.infrastructure.* or checkout_schema.*

module billing:
  exposes:      BillingApi.authorize(paymentInstruction)
  owns:         billing_schema.charges

module shipping:
  depends on:   CheckoutApi events/contracts only, never checkout tables

allowed dependencies:
  interface -> application -> domain
  infrastructure -> application/domain ports
  checkout.application -> inventory.api + billing.api

denied by architecture tests:
  *.infrastructure -> anotherModule.infrastructure
  anyModule.domain -> webFramework | jdbc | anotherModule.domain
  any cross-schema SQL join or repository import

future extraction seam:
  move checkout artifact + checkout_schema to Order Service
  replace InventoryApi/BillingApi local adapters with remote adapters
  keep application handlers and domain unchanged behind the same ports

Rubric

  • Module boundaries: Passes if each module names its public API and forbidden dependencies, and architecture checks reject repository imports and cross-schema SQL.
  • Data ownership: Passes if every table or schema has exactly one owning module and other modules request data through that owner’s API.
  • Dependency direction: Passes if application use cases depend on ports and domain types, while web and database adapters depend inward rather than the reverse.
  • Layer placement: Passes if interface, application, domain, and infrastructure responsibilities are shown within modules instead of four global packages shared across the system.
  • Transactional scope: Passes if the checkout design identifies its local transaction and does not claim an atomic database transaction across independently owned module schemas without an explicit coordinator.
  • Extraction path: Passes if the future order service lists the code and data to move plus the API adapters to replace, with no broker required for the current deployment.
  • Team fit: Passes if the design retains one artifact, pipeline, and on-call rotation and does not introduce service discovery or independent deployment obligations.