Why this matters
- Splitting into microservices too early creates distributed debugging, data consistency headaches, and deployment choreography for problems a well-structured monolith solves.
- Modulith packages catalog, orders, and payments as separate Java modules with explicit APIs — the compiler and ArchUnit tests catch cross-module violations before they reach production.
- When a module genuinely needs independent scaling, you extract it into a microservice with clear boundaries already defined.
Modular monolith
L1 · FresherOne deployable with explicit module boundaries — catalog, orders, payments — enforced by package rules.
Spring Modulith
L2 · IntermediateVerifies module APIs via tests and documents event flows between modules inside BookStore.
Before microservices
L3 · AdvancedExtract services only when independent scaling or team autonomy justifies network overhead.
Module events
L4 · ExpertUse application module events as stepping stone to Kafka without premature distribution.
Servlet FilterEncoding, CORS
Security Filter ChainAuth, CSRF
DispatcherServlet
HandlerInterceptorPre/post handle
Controller
Modulith building blocks
- Application modules — top-level packages (
catalog,orders,payments) each exposing an API package. @ApplicationModule— marks a module and its allowed dependencies.- Module events — typed events published within the monolith, with optional externalisation to Kafka later.
ApplicationModuleTest— verifies module structure: no illegal dependencies, no cycles.@NamedInterface— explicitly exposes types that other modules may depend on.
Package structure
com.bookstore
├── BookStoreApplication.java
├── catalog/
│ ├── CatalogModule.java // @ApplicationModule
│ ├── api/
│ │ ├── BookCatalogApi.java // public facade
│ │ └── BookSummary.java // shared DTO
│ ├── internal/
│ │ ├── BookController.java
│ │ ├── BookService.java
│ │ └── BookRepository.java
│ └── events/
│ └── BookPriceChanged.java
├── orders/
│ ├── OrdersModule.java
│ ├── api/
│ │ └── OrderPlacementApi.java
│ └── internal/
│ ├── OrderController.java
│ └── OrderService.java
└── payments/
├── PaymentsModule.java
└── internal/
└── PaymentService.java
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Module declaration and API facade
- Cross-module communication via events
- Verify module structure in tests
Test yourself
Answer these before moving on — recall is what makes it stick.