Microservices vs Monolith and the Modular Middle Path
Compare microservices and a monolith by team size, deployment, data and operations, and see why a modular monolith is the right starting point for most.

"Should we use microservices?" is the wrong question when asked first. The useful question is which problem you are trying to solve, and whether the cost of the answer is worth it. Microservices solve problems of team independence and uneven scaling. They create problems of networks, data consistency and operations. This comparison states the costs plainly and recommends a middle path. The code-level technique is in building a modular monolith with Spring Modulith.
The comparison
| Monolith | Microservices | |
|---|---|---|
| Deployable units | One | Many |
| Calls between parts | In-process method calls | Network calls (HTTP, gRPC, messages) |
| Transactions across parts | One database transaction | Sagas, eventual consistency |
| Scaling | The whole application | Each service separately |
| Release | One pipeline, all or nothing | Per service, independent |
| Failure modes | Process crash | Partial failure, timeouts, retries |
| Debugging | One stack trace | Distributed tracing needed |
| Team coordination | Shared codebase | Contracts between teams |
| Infrastructure | Simple | Orchestration, service discovery, observability |
What microservices actually buy you
Independent deployment. A team ships without coordinating with others, if the boundaries are right. Independent scaling. A hot component gets more instances without scaling everything. Technology freedom. A service can use a different language or database. Fault isolation. One service failing need not take everything down, if the callers handle it.
What they cost
Every call that was a method invocation becomes a network call that can be slow, fail or arrive twice. You need timeouts, retries and circuit breakers, idempotent operations, service discovery, distributed tracing, per-service deployment pipelines and contract tests. Data that was one transaction becomes a sequence of local transactions with compensation. A report that joined three tables becomes three API calls or a replicated read model. These are solvable and cost engineering time every day.
The distributed monolith
The worst result is services that must be deployed together, share a database or call each other in long synchronous chains. You keep all the costs and none of the benefits. It happens when boundaries are drawn before the domain is understood, usually along technical layers (an "auth service", a "database service") instead of business capabilities.
The modular monolith
One deployable application, internally divided into modules with explicit boundaries:
com.shop
catalog/ public API: CatalogApi, events
ordering/ public API: OrderingApi, events
billing/ public API: BillingApi, eventsModules call each other through a small public interface or events, never into each other's internals, and each owns its own tables. The compiler and a test enforce the rules (Spring Modulith checks them). You get most of the design discipline of services without the network. When a module needs independent scaling or a team of its own, you extract it along a boundary that already exists, as in splitting a monolith without a big bang.
When to choose microservices
- Many teams (a rough threshold is more than 30 to 50 engineers) are blocked on a shared release.
- Parts of the system have very different scaling or availability needs.
- Regulatory or security boundaries require isolation.
- The domain is well understood, and the boundaries have been stable.
When to stay with a monolith
- A small team that needs to move fast.
- A new product where the domain model is still changing.
- No platform team to run the infrastructure.
- No evidence yet of a scaling problem a monolith cannot handle.
The verdict
For most teams: start with a modular monolith. Draw the boundaries with domain-driven design, keep them strict, and extract a service when a concrete reason appears. That is cheaper than starting with services and finding the boundaries wrong, because moving a boundary inside a monolith is a refactoring, and moving it between services is a migration.
The same call, in process and over the network
The difference between the two architectures shows up in a few lines. In a modular monolith the ordering module asks the catalog module for a price through its public interface:
package com.shop.catalog;
public interface CatalogApi {
Price priceOf(String sku);
}
package com.shop.ordering;
@Service
class PlaceOrder {
private final CatalogApi catalog;
PlaceOrder(CatalogApi catalog) {
this.catalog = catalog;
}
Order place(String sku, int quantity) {
Price price = catalog.priceOf(sku); // a method call, nanoseconds
return new Order(sku, quantity, price.times(quantity));
}
}Now extract the catalog into its own service. The interface stays, and the implementation becomes a client with all the concerns a network brings:
@Component
class RemoteCatalog implements CatalogApi {
private final RestClient http;
RemoteCatalog(RestClient.Builder builder) {
this.http = builder.baseUrl("http://catalog")
.requestFactory(timeouts(Duration.ofMillis(300), Duration.ofSeconds(1)))
.build();
}
@Override
@Retryable(retryFor = ResourceAccessException.class, maxAttempts = 2)
public Price priceOf(String sku) {
return http.get().uri("/prices/{sku}", sku).retrieve().body(Price.class);
}
}Look at what appeared: a base URL that must resolve, a connect timeout and a read timeout, a retry that is only safe because the call is a read, and failure modes (timeout, 503, a half-deployed version) that the in-process call did not have. None of this is hard. It is the daily cost the table calls "partial failure", and it multiplies with every dependency. The reason to keep the interface from the start is that the extraction then changes one class, not every caller.
Enforce the boundaries before you need them
A modular monolith only works if the boundaries hold. Without enforcement, the ordering package imports a catalog internal class within a month. Spring Modulith can verify the structure in a test:
class ModularityTests {
static final ApplicationModules modules = ApplicationModules.of(ShopApplication.class);
@Test
void modulesRespectEachOthersBoundaries() {
modules.verify();
}
@Test
void writeDocumentation() {
new Documenter(modules).writeModulesAsPlantUml();
}
}verify() fails the build when a module reaches into another's internal package or when modules form a dependency cycle. If you prefer a library with no Spring dependency, ArchUnit expresses the same rule:
@AnalyzeClasses(packages = "com.shop")
class ArchitectureTest {
@ArchTest
static final ArchRule orderingDoesNotTouchCatalogInternals =
noClasses().that().resideInAPackage("..ordering..")
.should().dependOnClassesThat().resideInAPackage("..catalog.internal..");
}A failing test on day one is a conversation. A violation found in a year is a migration.
Events replace cross-module transactions
The other seam to prepare is data. In a monolith it is tempting to join across modules in one SQL query and one transaction. Keep each module's tables private and let modules react to each other through events, which map directly onto messages if the module is ever extracted:
@Service
class PlaceOrder {
private final ApplicationEventPublisher events;
private final OrderRepository orders;
@Transactional
Order place(String sku, int quantity) {
Order order = orders.save(new Order(sku, quantity));
events.publishEvent(new OrderPlaced(order.id(), sku, quantity));
return order;
}
}
@Component
class Reservations {
@ApplicationModuleListener
void on(OrderPlaced event) {
// reserve stock in the inventory module's own tables, in its own transaction
}
}The listener runs after the order's transaction commits, in its own transaction. That is the same consistency model as services: eventual, with a failure mode you must handle (what happens if reservation fails after the order exists). Learning to handle it while both sides are in one process, with a debugger attached, is far cheaper than learning it between two services at 2 a.m.
A decision test you can run this week
Ask four questions about the part you are tempted to extract. Does a separate team own it? Does it need a different scaling profile that costs real money today? Does it change on a different cadence from its neighbours? Can its data be owned entirely by it? Four yeses justify the extraction, and fewer than three means the module boundary is enough for now. Write the answers in the design note, so that the next person can see why the line was drawn there.
Where this does not apply
Organizations that already run a mature platform with templates for new services pay less per service. Teams building on serverless functions are in a different cost structure. The Spring Modulith reference covers the modular approach, and Martin Fowler's note on monolith-first states the argument.


