Frameworks & Languages
Spring Boot: Microservices or a Modular Monolith?
Spring Boot is often equated with microservices, but many new Java systems are better started as a modular monolith. Here is what microservices really cost, how Spring Modulith enforces boundaries, and how to extract services when the time comes.

Spring Boot is closely associated with microservices, and many teams starting a new Java system assume they should begin with a dozen small services, an API gateway and a message broker. Some of those teams later find they have built a distributed system before they needed one: every feature touches several repositories, local development needs a cluster, and a simple bug becomes a hunt through traces across services.
In our Java and Spring Boot development work, the first architecture question is not which services to create but whether to split at all. Often the better start is a modular monolith: one deployable Spring Boot application with strong internal boundaries that could become separate services later. This article explains how to choose, and how to keep that option open.
What Microservices Actually Cost
Microservices solve real problems, but each service boundary adds work that a single application does not have:
- Network failure handling. Every call between services can time out or fail, so you need timeouts, retries, circuit breakers and idempotent operations.
- Data consistency. With a database per service, a business operation spanning several services cannot use one transaction. You need sagas, the transactional outbox pattern and compensating actions.
- Observability. Distributed tracing with Micrometer Tracing and OpenTelemetry, correlated logs and per-service metrics become essential rather than optional.
- Platform and delivery. Separate pipelines, versioned contracts between services, service discovery or Kubernetes, an API gateway such as Spring Cloud Gateway, and centralised configuration.
- Testing across boundaries. Contract tests and environment-level tests replace much of what a single integration test suite did before.
For a large organisation with many teams these costs are worth paying. For a single team, they can consume much of the budget that should go into features. We made a similar point about infrastructure in do you actually need Kubernetes.
What a Modular Monolith Looks Like in Spring Boot
A modular monolith is one application and usually one database, but its code is divided into modules that mirror business capabilities, such as orders, inventory, billing and customers. The rules are strict:
- Each module exposes a small public API, typically a service interface and a few data types, and keeps everything else internal.
- Modules never reach into each other's internals or repositories, and each owns its own tables.
- Where one module needs to react to another, it listens for events rather than calling into it directly.
Spring Modulith, an official Spring project, makes this practical. It treats each top-level package under the main application package as a module, and a single test using ApplicationModules.of(Application.class).verify() fails the build if a module depends on another module's internals or if there are dependency cycles. Modules publish ordinary Spring application events, and listeners annotated with @ApplicationModuleListener run asynchronously after the publishing transaction commits. The event publication registry stores events in the database so they are not lost if the application stops mid-way. Modulith can also test one module in isolation with @ApplicationModuleTest and generate documentation diagrams of the module structure.
The result keeps the simplicity of one deployment, one transaction where needed and one place to debug, while giving the clear boundaries that make later extraction possible.
When Microservices Are the Right Call
We recommend splitting into separate services when one or more of these is genuinely true:
- Independent teams. Several teams need to release on their own schedules without coordinating every deployment.
- Very different scaling needs. One part of the system, such as ingestion or search, needs many times the resources of the rest.
- Different runtime requirements. A component needs a different language, a GPU, a separate security zone or its own compliance boundary.
- Isolation of failure. A non-critical component must not be able to take down critical paths such as payments.
- Integration at the edges. Adapters to legacy or partner systems with their own release cycles often sit well as separate services, a pattern we discuss in Spring Boot for enterprise integration.
If none of these applies yet, a modular monolith is usually cheaper to build, run and change.
Extracting a Service When the Time Comes
The advantage of well-enforced modules is that extraction becomes a planned step rather than a rewrite:
- Move the module's tables to their own schema or database, which is easy if no other module was allowed to query them.
- Externalise its events. Spring Modulith can publish selected application events to Kafka, RabbitMQ or other brokers, so other modules keep receiving them once the module runs elsewhere.
- Replace in-process calls to the module's public API with an HTTP or messaging client behind the same interface.
- Deploy and monitor the new service alongside the monolith, then remove the module from the original codebase.
The data side of this deserves care, particularly where reporting queries joined across modules; our database development team plans those changes. Event-driven designs like this also appear in event-driven integration between a warehouse and a webshop.
Practical Defaults for a New Spring Boot System
- Start with a modular monolith on a current Spring Boot release and Java 21 LTS or later, with module boundaries verified in CI.
- Use virtual threads for request handling where the workload is mostly blocking I/O; Spring Boot enables them with a single property.
- Use Flyway migrations, with each module's tables clearly named and owned.
- Add metrics, health checks and tracing through Spring Boot Actuator and Micrometer from day one, even with one service.
- Package as a container from the start, so moving to separate services or a managed platform needs no change to the build. Our Docker and Kubernetes and cloud DevOps teams set this up.
Talk It Through
The right architecture depends on your teams, your release needs and how the system is expected to grow. If you are planning a new Java platform or untangling a microservices estate that has become hard to change, contact us and we will review the options with you.
Frequently Asked Questions
Is a modular monolith just a polite name for a big ball of mud?
No. The difference is enforcement. A modular monolith has explicit modules with small public APIs, each owning its own data, and the build fails if one module reaches into another's internals. Without that enforcement, any single application drifts towards tangled dependencies, which is exactly what makes later changes and extractions expensive.
Can a modular monolith scale to high traffic?
Yes, in most cases. A stateless Spring Boot application can run as many identical instances behind a load balancer, and the database is usually the real limit long before the application is. Separate services become worthwhile when one specific part needs to scale very differently from the rest, not simply because traffic is growing.
We already have microservices that are hard to change. Can they be merged back?
They can, and it is more common than people expect. Services that always change and deploy together are good candidates for consolidating into modules of a single application, keeping separate services only where independent scaling, ownership or isolation really matters. This is done gradually, one pair of services at a time.
Does Spring Modulith lock us into a particular architecture?
No. It is a library that verifies package structure and adds helpers for events, testing and documentation. Your code stays ordinary Spring Boot code. If you later extract a module into its own service, the module's public interface and events become the contract, and Spring Modulith can publish those events to a message broker.
How long does it take to decide on the right architecture?
For most projects, a short discovery phase is enough: mapping business capabilities, team structure, release needs, scaling hotspots and integrations. That usually makes clear whether separate services are justified from day one or whether a modular monolith with planned extraction points is the better start.








