The modular monolith course from Milan Jovanovic
A modular monolith is an architectural pattern that structures the application into independent modules or components with well-defined boundaries. The modules are split based on logical boundaries, grouping together related functionalities. This approach significantly improves the cohesion of the system.
The modules are loosely coupled, which further promotes modularity and separation of concerns. Modules communicate through a public API.
- High cohesion
- Loose coupling
- Simplified deployment
- Improved performance
- Lower operational complexity
- Easier transition to microservices
- Must be independent and interchangeable
- Must be able to provide the required functionality
- Must have a well-defined interface exposed to other modules
- Logical isolation between modules
- Modules must talk through a public API
- Module data must be isolated in the database
- Method calls
- Messaging
- Speed of in-memory calls
- Easy to implement
- No indirection
- High availability
- Loose coupling
- Level 1: Separate tables
- Level 2: Separate schemas
- Level 3: Separate databases
- Level 4: Separate servers
NEVER directly call another module's database!
If you need data from another module:
- Use the public API.
- Messaging (fat events)
- Data copy
How to define your domain model?
- Discover
- Decompose
- Connect
- Code
- Event storming
- Bounded contexts
- Write up the domain events using sticky notes.
- Create a timeline