Modular Monolith Architecture Blueprint: High Scale Without Distributed Chaos

Introduction: Do You Really Need Microservices?
Microservices have become one of the most popular architectural patterns for modern backend systems.
The usual story sounds familiar:
Start with a monolith.
The application grows.
The codebase becomes difficult to maintain.
The engineering team grows.
Then the solution appears obvious: split the application into dozens of independent microservices.
But there is a problem.
Microservices do not automatically solve poor architecture.
They move many problems from the code level to the distributed-systems level.
A simple function call becomes an HTTP or RPC request. A database transaction can become a distributed consistency problem. A local development environment can require multiple databases, queues, caches and service containers. Debugging one user request may require following traces across several independently deployed systems.
That does not mean microservices are bad.
They are extremely useful when an organization genuinely needs independent deployment, independent scaling, technology diversity or strong organizational boundaries. Martin Fowler's analysis of microservices highlights both their benefits and their costs, particularly the complexity introduced by distribution and eventual consistency.
For many applications, there is another option:
The Modular Monolith
A modular monolith is a single deployable application that is internally divided into well-defined business modules with strict architectural boundaries.
Instead of creating:
Identity Service
Billing Service
Order Service
Inventory Service
Notification Service
Analytics Service
...you can initially build:
One Application
│
├── Identity Module
├── Billing Module
├── Order Module
├── Inventory Module
├── Notification Module
└── Analytics ModuleThe application is deployed as one unit, but the code is organized as if those boundaries matter.
And they do.
The goal is not simply to keep everything in one application.
The goal is to create a modular system that can evolve into independently deployable services later if there is a real reason to do so.
What Is a Modular Monolith?
A modular monolith combines two ideas:
Monolithic deployment
Strong internal modularity
The entire backend runs as one deployable application.
However, each business domain owns its implementation details and exposes only explicitly defined interfaces to other modules.
For example:
src/
├── modules/
│ ├── identity/
│ │ ├── internal/
│ │ │ ├── repositories/
│ │ │ ├── services/
│ │ │ └── entities/
│ │ ├── api/
│ │ │ ├── identity.service.ts
│ │ │ └── identity.dto.ts
│ │ └── identity.module.ts
│ │
│ ├── billing/
│ │ ├── internal/
│ │ │ ├── repositories/
│ │ │ ├── payment-gateways/
│ │ │ └── invoicing/
│ │ ├── api/
│ │ │ └── billing.service.ts
│ │ └── billing.module.ts
│ │
│ ├── orders/
│ │ ├── internal/
│ │ ├── api/
│ │ └── orders.module.ts
│ │
│ └── notifications/
│ ├── internal/
│ ├── listeners/
│ └── notifications.module.ts
│
└── shared/
├── logging/
├── database/
└── events/The important part is not the folder names.
The important part is the dependency architecture.
Modular Monolith vs Traditional Monolith
A monolith is not automatically a bad architecture.
The real problem is an unstructured monolith.
A traditional spaghetti monolith often looks like this:
Controller
↓
Service
↓
Database Model
↓
Another Module
↓
Another Database ModelAnything can call anything.
Over time:
billing accesses user tables directly
orders modify inventory state
controllers contain business logic
shared models become global dependencies
database relationships become impossible to reason about
changing one domain breaks another
This is sometimes called a Big Ball of Mud.
A modular monolith attempts to prevent this by making architectural boundaries explicit.
Martin Fowler has also pointed out that a monolithic application can have good modular structure; the monolith itself is not synonymous with poor architecture.
The 3 Core Rules of Modular Monolith Architecture
1. Private by Default
A module should hide its implementation details.
For example:
billing/
├── internal/
│ ├── invoice.repository.ts
│ ├── payment.gateway.ts
│ └── billing.service.ts
│
└── api/
└── billing.facade.tsOther modules should not import:
billing/internal/payment.gatewayInstead, they should interact with the public API:
billing/api/billing.facadeThis creates a stable contract between modules.
2. Communicate Through Contracts
Suppose the billing module needs information about a customer.
This is dangerous:
const user = await userRepository.findById(userId);if userRepository belongs to the identity module.
Instead:
const user = await identityService.getCustomer(userId);The billing module does not need to know:
which database is used
how users are stored
which ORM is being used
how the identity module validates users
It only knows the contract.
This is one of the most important principles of modular architecture:
Depend on capabilities, not implementation details.
3. Avoid Cross-Domain Database Access
If billing owns:
billing.invoices
billing.payments
billing.refundsthen identity should not directly query those tables.
Likewise, billing should not directly manipulate:
identity.users
identity.sessions
identity.credentialsThe database may physically exist in the same PostgreSQL instance, but ownership should remain clear.
This makes future extraction significantly easier.
Modular Monolith vs Microservices
The biggest difference is not simply "one application versus many applications."
The deeper difference is where the system boundary exists.
Engineering Factor | Spaghetti Monolith | Modular Monolith | Microservices |
|---|---|---|---|
Deployment | Single | Single | Multiple |
Code boundaries | Weak | Strong | Strong |
Network calls | Minimal | Minimal | Frequent |
Database | Shared | Logically isolated | Usually decentralized |
Transactions | Simple | Mostly local | Distributed concerns |
Debugging | Simple but messy | Relatively simple | Distributed tracing |
Infrastructure | Low | Low–Moderate | Higher |
Independent deployment | No | No | Yes |
Independent scaling | Limited | Limited | Strong |
Technology diversity | Limited | Limited | Strong |
Operational complexity | Low initially | Low | High |
Team autonomy | Low | Medium–High | High |
Microservices strengthen boundaries by physically separating services, but that separation introduces distributed-system costs such as network failures and consistency challenges.
Why Choose a Modular Monolith?
1. Lower Operational Complexity
One application generally means fewer moving parts.
Instead of managing:
20 services
5 databases
3 message brokers
service discovery
API gateways
distributed tracing
multiple deployment pipelinesyou may only need:
Application
Database
Cache
Queue
MonitoringThe exact infrastructure depends on the product, but the operational surface can remain substantially smaller.
2. Faster Local Development
Developers can run the entire application without starting dozens of services.
That can significantly reduce:
setup time
memory usage
network configuration
debugging complexity
environment inconsistencies
This is particularly valuable for smaller engineering teams.
3. Easier Transactions
One of the strongest advantages is transactional simplicity.
Suppose an order requires:
Create Order
↓
Create Payment Record
↓
Update Order StatusInside one application and database transaction, this can remain an ordinary ACID transaction.
With distributed services, the same workflow may require coordination across independent services and databases, introducing eventual consistency or distributed transaction patterns.
Microservices architectures commonly require careful handling of eventual consistency.
4. Easier Debugging
Consider a request:
POST /checkoutIn a modular monolith:
HTTP Request
↓
Checkout Module
↓
Order Module
↓
Billing Module
↓
DatabaseIn a distributed architecture:
API Gateway
↓
Checkout Service
↓
Order Service
↓
Billing Service
↓
Payment Service
↓
DatabaseThe second architecture may be completely justified at scale.
But it also requires stronger observability.
Database Design for a Modular Monolith
Database design is where many modular monolith implementations fail.
Simply creating folders called billing and identity does not create real boundaries.
The data model needs ownership boundaries too.
For PostgreSQL, logical schemas can help:
CREATE SCHEMA identity_module;
CREATE SCHEMA billing_module;
CREATE SCHEMA inventory_module;
CREATE TABLE identity_module.users (
id UUID PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE billing_module.invoices (
id UUID PRIMARY KEY,
user_id UUID NOT NULL,
amount_cents INT NOT NULL,
status VARCHAR(50) NOT NULL
);Notice that billing_module.invoices.user_id is a logical reference rather than a cross-domain foreign key.
That makes ownership clearer.
If billing eventually becomes its own service, its database model does not have to untangle a large network of cross-domain foreign keys.
However, schema isolation is not mandatory for every project. A smaller application may use table naming conventions or separate database users and permissions instead.
The principle is more important than the exact mechanism:
Every domain should know which data it owns and which data it merely consumes.
Domain Events in a Modular Monolith
Not every interaction needs a direct service call.
Consider an order completion workflow.
A naive implementation might look like:
await orderService.complete();
await inventoryService.reserve();
await emailService.sendConfirmation();
await analyticsService.track();The order service now knows too much.
A better approach can be an in-process domain event:
export class OrderCompletedEvent {
constructor(
public readonly orderId: string,
public readonly userId: string,
public readonly totalAmount: number,
public readonly occurredAt: Date
) {}
}Then:
await eventBus.publish(
new OrderCompletedEvent(
order.id,
userId,
order.totalAmount,
new Date()
)
);Other modules can subscribe:
OrderCompleted
│
├── Inventory Listener
├── Notification Listener
├── Analytics Listener
└── Loyalty ListenerThis reduces direct coupling.
However, there is an important production consideration:
An in-memory event bus is not automatically reliable.
If the process crashes after the database transaction commits but before an event is processed, the event may be lost.
For critical workflows, consider patterns such as:
transactional outbox
durable message queues
retry policies
idempotent consumers
dead-letter queues
A modular monolith does not eliminate distributed-systems thinking; it lets you introduce it only where it provides value.
Enforcing Module Boundaries Automatically
Architecture rules that exist only in documentation eventually become suggestions.
Automate them.
Tools such as dependency-cruiser can define forbidden dependency relationships and fail builds when architectural rules are violated. Its rule system supports forbidden dependencies with configurable severity, including errors that can make a build fail.
A simplified example:
module.exports = {
forbidden: [
{
name: "no-cross-module-internal-imports",
severity: "error",
from: {
path: "^src/modules/"
},
to: {
path: "^src/modules/[^/]+/internal/"
}
}
]
};Your CI pipeline can then enforce:
Developer commits code
↓
Dependency analysis
↓
Boundary violation?
/ \
Yes No
↓ ↓
Fail BuildThis turns architectural principles into enforceable engineering constraints.
Testing Strategy for a Modular Monolith
Testing becomes easier when module boundaries are explicit.
A strong test strategy can contain three layers.
Unit Tests
Test internal business logic independently.
Billing Module
├── InvoiceService tests
├── PaymentRules tests
└── RefundPolicy testsModule Integration Tests
Test the module against its database and infrastructure.
Billing Module
↓
Test DatabaseContract Tests
Test the public interfaces between modules.
Identity API
↓
Billing ConsumerThe goal is to make internal implementation details replaceable without breaking consumers.
A Practical Modular Monolith Architecture
A mature backend might look like this:
src/
├── modules/
│
│ ├── identity/
│ │ ├── api/
│ │ ├── application/
│ │ ├── domain/
│ │ ├── infrastructure/
│ │ └── module.ts
│ │
│ ├── orders/
│ │ ├── api/
│ │ ├── application/
│ │ ├── domain/
│ │ ├── infrastructure/
│ │ └── module.ts
│ │
│ ├── billing/
│ │ ├── api/
│ │ ├── application/
│ │ ├── domain/
│ │ ├── infrastructure/
│ │ └── module.ts
│ │
│ └── notifications/
│ ├── api/
│ ├── application/
│ ├── domain/
│ ├── infrastructure/
│ └── module.ts
│
├── shared/
│ ├── logging/
│ ├── configuration/
│ └── events/
│
└── main.tsThis structure works particularly well with domain-driven design principles because the code organization reflects business capabilities rather than technical layers alone.
When Should You Choose a Modular Monolith?
A modular monolith is often a strong default when:
your team is small or medium-sized
the product is still evolving
requirements change frequently
you need strong transactional consistency
local development speed matters
infrastructure resources are limited
the domains are related
you do not yet know which components genuinely need independent scaling
operational simplicity is more valuable than independent deployments
The important point is not that every application should be a modular monolith.
It is that architecture should solve an actual problem rather than a hypothetical future problem.
When Should You Move to Microservices?
Microservices become more attractive when there is a concrete requirement that the monolith cannot satisfy efficiently.
Examples include:
Independent Scaling
Suppose:
API Traffic = 1x
Messaging Traffic = 100xIf real-time messaging requires dramatically different scaling characteristics, extracting it may make sense.
Independent Deployment
If several large engineering teams repeatedly block each other because every change requires coordinating one application release, independent services can provide meaningful organizational benefits.
Technology Heterogeneity
A domain may require technology that does not fit naturally into the main application.
Examples:
GPU-based machine learning inference
video processing
specialized data processing
high-throughput streaming infrastructure
Strong Organizational Boundaries
As organizations grow, independent teams may need ownership over independently evolving business capabilities.
However, team size alone should not be treated as a universal threshold.
There is no magic number of engineers at which microservices suddenly become correct.
The architecture should follow the organization's actual constraints.
How to Evolve a Modular Monolith Into Microservices
One of the biggest advantages of modular architecture is that it creates a potential extraction path.
Instead of:
Spaghetti Monolith
↓
Massive Rewrite
↓
Microservicesyou can aim for:
Spaghetti Monolith
↓
Modular Monolith
↓
Identify Real Scaling/Ownership Boundary
↓
Extract One Module
↓
Independent ServiceThis is an incremental approach.
Martin Fowler's guidance on decomposing monoliths similarly emphasizes extracting business capabilities rather than arbitrarily splitting code into small services.
For example:
Before:
Application
├── Identity
├── Orders
├── Billing
├── Notifications
└── AnalyticsLater:
Main Application
├── Identity
├── Orders
└── Billing
Notification Service
Analytics ServiceEventually:
Identity Service
Order Service
Billing Service
Notification Service
Analytics ServiceBut only if the business actually needs that complexity.
Common Modular Monolith Mistakes
Mistake 1: Creating Modules but Sharing Everything
If every module can directly access every repository, you have not created meaningful boundaries.
Mistake 2: One Giant Shared Database Model
Shared entities often become hidden coupling points.
Mistake 3: Putting Everything in shared/
A shared folder can become the new global dumping ground.
Only genuinely cross-cutting infrastructure should normally live there.
Mistake 4: Excessive Event Usage
Events are useful for decoupling.
They can also make workflows difficult to understand if every operation becomes asynchronous.
Use direct calls for simple request-response interactions and events when decoupling or eventual processing provides a real benefit.
Mistake 5: Designing for Microservices Before You Need Them
Do not introduce network boundaries simply because you might need them someday.
Build strong module boundaries first.
Modular Monolith Best Practices
Use these principles when designing a modular backend:
Organize code around business domains.
Make module internals private.
Expose explicit public contracts.
Give every module clear data ownership.
Avoid cross-domain database writes.
Avoid unnecessary cross-domain joins.
Use domain events where they reduce coupling.
Make event consumers idempotent.
Automate dependency-boundary checks.
Keep shared infrastructure deliberately small.
Test module contracts.
Monitor module-level performance.
Design extraction seams before extraction becomes necessary.
Introduce microservices only when a measurable problem justifies them.
Modular Monolith Architecture Checklist
Before calling your backend a modular monolith, ask:
Are modules organized around business capabilities?
Does each module have clear ownership?
Are internal implementations hidden?
Do modules communicate through public contracts?
Are cross-module database writes prohibited?
Are cross-domain joins carefully controlled?
Is the shared layer intentionally small?
Are architectural boundaries tested automatically?
Are important domain events reliable?
Are event consumers idempotent?
Can each module be tested independently?
Could a high-value module eventually be extracted?
Is there a measurable reason to introduce microservices?
If most answers are yes, you are probably building a genuinely modular monolith rather than simply calling a traditional monolith "modular."
Frequently Asked Questions
Is a modular monolith better than microservices?
Not universally.
A modular monolith is often simpler to build, deploy and operate, while microservices provide stronger physical isolation, independent deployment and independent scaling.
The right choice depends on the organization's technical and business constraints.
Can a modular monolith scale?
Yes.
Scalability is not exclusive to microservices.
A modular monolith can be deployed across multiple application instances behind a load balancer and supported by caching, queues, database scaling and appropriate infrastructure.
The question is whether individual parts need to scale independently.
Is a modular monolith the same as a monolith?
Not exactly.
Both may be deployed as a single application, but a modular monolith deliberately enforces internal boundaries between business domains.
Can a modular monolith use domain-driven design?
Absolutely.
Domain-driven design can be particularly useful for identifying bounded contexts, business capabilities and module boundaries.
Can a modular monolith later become microservices?
Yes.
Strong module boundaries can make future extraction easier.
However, extraction is not automatic. Database ownership, communication contracts, operational requirements and consistency models still need to be redesigned.
Should every module have its own database?
Not necessarily.
A modular monolith can use one database instance with logical schemas or strict ownership rules.
The important concept is data ownership, not simply the number of database servers.
Are domain events necessary?
No.
Use them when they provide meaningful decoupling.
For straightforward operations that require an immediate result, a direct module API may be clearer.
Is a modular monolith cheaper than microservices?
It can be, particularly because fewer independently deployed components can reduce infrastructure and operational overhead.
But actual cost depends on traffic, infrastructure, observability, team size and application requirements.
Final Verdict: Build the Boundaries Before Building the Services
Microservices are not the definition of mature software architecture.
Good boundaries are.
A poorly designed monolith can become difficult to maintain.
A poorly designed microservices architecture can become even more difficult to maintain because the same coupling now exists across networks, databases and deployment pipelines.
The modular monolith offers a practical middle ground:
Strong Domain Boundaries
+
Single Deployment
+
Simple Transactions
+
Fast Local Development
+
Lower Operational Complexity
↓
Modular MonolithThe most valuable architectural decision is therefore not:
"How many services should we create?"
It is:
"Where should the boundaries of our business domains be?"
Start by creating those boundaries inside one application.
Make them explicit.
Make them testable.
Make them enforceable.
Then, if a particular domain eventually needs independent scaling, deployment, technology or ownership, you have a much stronger foundation from which to extract it.
Don't distribute complexity before you need distributed systems. Build a modular system first—and let real engineering constraints tell you when a service boundary is worth the cost.
Written by
Praxiaskill
Last updated
19 August 2026
