Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Several teams share one large Spring Boot monolith with tangled packages. Leadership wants microservices. Explain how you would use Spring Modulith as the first step, and how you would decide later which modules become separate services.

I would first make the monolith modular inside one deployable: map packages to business modules, introduce Spring Modulith's structure and run ApplicationModules.verify() in CI against a known-violations baseline that may only shrink, replace calls into other modules' internals with published APIs and events, and give each module an owning team, its own tables and its own module tests. Only later would I extract a module into a service, and only for a clear reason such as different scaling, release cadence, team autonomy or compliance, tracking coupling and incident data; many modules can stay in the modular monolith for good.

Why this question is asked

Leadership often asks for microservices when the real complaint is that the monolith is hard to change: every team steps on every other team, a change in one area breaks another, and releases are slow. Cutting a tangled monolith into services usually produces a tangled distributed system, which is worse. Interviewers ask this design question to see whether we can separate the goal, independent teams and safer change, from the mechanism, and use Spring Modulith as a low-risk first step. In this answer, we will map the modules, enforce them with a shrinking baseline, decouple them with APIs and events, give them owners and data, and then decide which modules should become services.

1Why Modules Come Before Services

A module, in Spring Modulith's sense, is a business area in its own top-level package with a small public API and hidden internals. A service is a module that also runs as its own process, with its own deployment, database and network interface. The hard part of both is the same: finding the boundaries and removing the hidden dependencies across them.

Doing that work inside one deployable is far cheaper. A wrong boundary is fixed by moving classes, with the compiler and tests to help, instead of by changing network APIs, data replication and deployments. So the first step towards microservices is a modular monolith, and it delivers value on its own: teams can work in their own module with fewer surprises.

2Mapping Packages and Enforcing a Shrinking Baseline

I would run a short workshop with the teams to name the intended business modules, for example orders, billing, inventory and customers, and map today's packages onto them. Then we restructure the code so each module is a direct sub-package of the application package, which is Spring Modulith's default way to detect modules.

Running ApplicationModules.verify() on a tangled codebase will produce hundreds of violations. Failing the build on all of them would stop every team, so I would record today's violations as a baseline file and fail only when a new one appears. When a violation is fixed, it is removed from the baseline, so the list can only shrink.

Java
@Test
void noNewModuleViolations() throws IOException {
List<String> baseline = Files.readAllLines(Path.of("src/test/resources/modulith-baseline.txt"));
List<String> current = ApplicationModules.of(Application.class).detectViolations().getMessages();
assertThat(current).isSubsetOf(baseline); // a new violation fails the build
assertThat(baseline).isSubsetOf(current); // a fixed one must be removed from the file
}
// week 1: 412 violations in the baseline; week 12: 96

Notice the second assertion. It forces the file to be updated when someone fixes a violation, so the baseline really reflects the code and the number we report to leadership is honest. Check your version for the exact API that returns the violation messages.

3Replacing Internal Calls With APIs and Events

Each violation is a place where one module reaches into another's internals. There are two ways to fix it. When a module needs an answer now, it calls a published API in the other module's base package, for example a method on OrderQueries that returns a small read model instead of the order entity. When a module only needs to react to something that happened, the publishing module sends an application event, such as OrderCompleted, and the other module listens with @ApplicationModuleListener.

Events reduce coupling the most, because the publisher does not know who listens. With Spring Modulith's event publication registry, events are stored in the publisher's transaction and retried if a listener fails, so moving to events does not lose reliability. The Documenter can generate diagrams of the module dependencies after each change, which gives each team a picture of what still connects to them.

Fixing a cross-module dependency
BeforeAfterWhy
billing uses orders.internal.OrderRepositorybilling calls orders.OrderQueriesAPI is stable; internals can change
orders calls inventory.internal.StockServiceorders publishes OrderCompletedorders no longer knows about inventory
shared entity Customer used everywhereeach module keeps the fields it needsremoves the widest coupling
Each fix removes one line from the violation baseline.

4Owners, Data and Module Tests

Boundaries only last if someone defends them. I would give every module an owning team, recorded in the code ownership file so that changes to a module need its team's review. Then data: each module gets its own tables, ideally its own schema, and no other module queries them directly. Shared tables are the strongest hidden coupling in a monolith and the main obstacle to any later extraction.

Finally, module-level tests with @ApplicationModuleTest boot one module with its own beans, and other modules' beans mocked. If a module's tests pass in isolation, it really is independent. This is also the best early sign of whether a module could run on its own as a service.

5Deciding Which Modules Become Services

Once the modules are clean, extraction becomes a business decision, not a rescue. I would extract a module only for a clear reason. Different scaling: search traffic is ten times that of the rest of the system. Different release cadence: pricing changes daily while the rest releases weekly. Team autonomy: a team is blocked by the shared release train. Compliance: payment data must run in an isolated environment. Without such a reason, a module stays in the monolith, which is a valid end state.

I would back the decision with data: coupling metrics, such as the number of calls and events between modules, and incident data, such as how often a change in one module caused a failure in another. Modules whose events are already externalized to Kafka are the easiest to cut out, because other modules already talk to them asynchronously.

Step throughShould this module become a service?
  1. Module is cleanno violations, own tables, passes module tests
  2. Clear reason: scaling, cadence, autonomy or compliance?
    YesCheck couplingNoKeep it in the modular monolith
  3. Low coupling, events already externalized?
    YesExtract it as a serviceNoReduce coupling first
  4. Measure after extractionlead time, incidents, cost

4 steps in order. Play them, or step through them one at a time.

6Follow-up questions

What would make you stop the extraction of a module?

If the data shows the module is still tightly coupled, for example it needs synchronous calls to two other modules for every request, or shares tables we cannot split. I would also stop if the reason disappears, such as the scaling problem being solved with caching, or if the first weeks show the cost, extra latency, operational work and data synchronisation, is higher than the benefit. Stopping early is cheap because the module still works inside the monolith.

How do you explain this plan to leadership who asked for microservices?

I would tie it to what they actually want: teams that can ship independently and fewer incidents caused by other teams. The modular monolith gives most of that within months, at low risk, and it is the necessary first step for any services we extract later. I would show progress with the shrinking violation count and team lead times.

Does Spring Modulith add runtime overhead?

Very little. The structure checks run in tests, and the runtime parts, such as event publication, use ordinary Spring events plus a database table for the registry if we choose to use it.

7Conclusion

In this answer, we used Spring Modulith as the first step from a tangled monolith: mapping packages to business modules, enforcing the structure with verify() and a shrinking baseline, replacing internal calls with APIs and events, and giving modules owners, their own tables and module tests. We then extract a module only for a clear reason such as scaling, release cadence, autonomy or compliance, guided by coupling and incident data, and accept that many modules may stay in the modular monolith.

What to say in the interviewAbout 80 seconds aloud

Open with

I would separate the goal from the mechanism. Leadership wants teams that can change things independently; services are one way to get that, but cutting a tangled monolith directly gives a tangled distributed system.

Then, if they want more

So step one is a modular monolith with Spring Modulith. We name the business modules with the teams, move code so each module is a direct sub-package, and add a test with ApplicationModules.verify.

Because a tangled codebase starts with hundreds of violations, I record them as a baseline and fail only on new ones, and the baseline may only shrink, which also gives leadership a progress number.

Then we fix violations: direct calls into another module's internals become calls to a small published API or application events with @ApplicationModuleListener, backed by the event publication registry. Each module gets an owning team, its own tables or schema, and @ApplicationModuleTest tests that boot it alone.

Only then do we consider extraction, and only for a clear reason, different scaling, release cadence, team autonomy or compliance, backed by coupling and incident data. Modules with externalized events are easiest to cut out. Many modules will stay in the modular monolith, and that is a valid end state.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Several teams share one large Spring Boot monolith with tangled packages. Leadership...": https://scrivio-interview-library.netlify.app/spring-boot/spring-projects/42047be294/