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.

Empty boardroom with a long table, high-backed chairs and floor-to-ceiling windows

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:

  1. Independent teams. Several teams need to release on their own schedules without coordinating every deployment.
  2. Very different scaling needs. One part of the system, such as ingestion or search, needs many times the resources of the rest.
  3. Different runtime requirements. A component needs a different language, a GPU, a separate security zone or its own compliance boundary.
  4. Isolation of failure. A non-critical component must not be able to take down critical paths such as payments.
  5. 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:

  1. Move the module's tables to their own schema or database, which is easy if no other module was allowed to query them.
  2. 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.
  3. Replace in-process calls to the module's public API with an HTTP or messaging client behind the same interface.
  4. 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.

How We Can Help

Services Related to This Article

The work we do with the technologies discussed above — with pricing, process and real examples on each page.

  • Java & Spring Boot Development

    Spring Boot microservices and enterprise Java applications — secure REST APIs, batch processing, messaging and integration with existing systems.

  • Database Development

    Schema design, query and index tuning, migrations and search infrastructure across MySQL, PostgreSQL, MongoDB, Redis and Elasticsearch.

  • Docker & Kubernetes

    Applications packaged in Docker, deployed with CI/CD, and run on Kubernetes when they need to scale — with monitoring, secrets and rollbacks built in.

  • Cloud Hosting & DevOps

    AWS, Azure, Google Cloud and DigitalOcean setup, Docker and Kubernetes, CI/CD pipelines, Nginx tuning, monitoring, backups and cost optimisation.

In Practice

Case Studies on This Topic

Projects where we put these ideas to work, each with a live demo.

  • Containers Bins — Kellner Industrie
    • Java 21
    • Spring Boot
    • Spring Batch

    Enterprise Integration

    Warehouse Order Service & Event Integration

    A Spring Boot order service processing 9,600 orders a day across four warehouses, with event-driven stock sync.

  • Highway Road — Vantage Telematics
    • NestJS
    • TypeScript
    • Kafka

    Backend API Development

    Fleet Telematics API Platform on NestJS

    A NestJS API platform that ingests 40 million vehicle events a day and serves partners, dashboards and mobile apps from one documented interface.

Keep Reading

  • Bearded man in a suit working on a laptop at a wooden table in afternoon sunlight

    Moving From .NET Framework to Modern .NET: A Practical Upgrade Path

    Many business applications still run on .NET Framework 4.x. Here is a practical path to modern .NET: choosing the target version, assessing Web Forms, WCF and MVC code, and migrating a live application route by route.

  • Close-up of a car instrument cluster with rev counter, speedometer and fuel and temperature gauges

    NestJS and TypeScript End to End: Sharing Types Between API and Front End

    A NestJS API and a TypeScript front end should not define the same shapes twice. We compare shared packages, OpenAPI-generated clients, Zod schemas and GraphQL codegen, and cover the details that cause contract bugs.

  • Close-up of a metal bicycle chain running over worn, oily sprockets

    Rust for Web Services: Where Its Safety and Speed Pay Off

    Rust is the wrong tool for most business web applications, but for parsing untrusted input, CPU-heavy hot paths and strict latency targets its safety and speed pay for themselves. Here is where it fits, what the stack looks like and what it costs.

Let’s Connect

Let’s Build Something Amazing Together

Share your project details and our experts will get back to you within one business day with the best solution — free consultation, no obligation.