Quick revision
The short answer
Start by making the event flows visible: inventory every event and listener, using Spring Modulith to document module dependencies and event flows. Then turn cross-module events into explicit, versioned contracts owned by the publishing module, remove any reliance on listener order by turning order-dependent flows into explicitly orchestrated workflows, decide per event whether delivery must be reliable and use a publication registry or outbox where it must, and lock the result in with tests of module boundaries and published events, such as Modulith's Scenario API.
What to remember
In this answer, we brought tangled module events under control without banning them. We made flows visible with an inventory and Spring Modulith's documentation, turned cross-module events into versioned contracts owned by the publisher, replaced reliance on listener order with explicitly orchestrated workflows, chose reliable delivery through a publication registry or outbox where losing an event is unacceptable, and locked the structure in with boundary verification and Scenario tests.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Start by making the event flows visible: inventory every event and listener, using Spring Modulith to document module dependencies and event flows. Then turn cross-module events into explicit, versioned contracts owned by the publishing module, remove any reliance on listener order by turning order-dependent flows into explicitly orchestrated workflows, decide per event whether delivery must be reliable and use a publication registry or outbox where it must, and lock the result in with tests of module boundaries and published events, such as Modulith's Scenario API.
Why this question is asked
Events between modules start as a good idea: modules stop calling each other, and adding a reaction is easy. A few years later the same monolith has dozens of listeners, some depending on running before others, some reading data they should not, and nobody can say what happens when an order is placed. Banning events would throw away the decoupling they bought. Interviewers ask this leadership question to see whether we can restore control incrementally. In this answer, we will make the flows visible, define contracts, remove ordering assumptions, decide reliability per event, and add the tests that keep the system from drifting back.
1Make the Flows Visible
We cannot fix what nobody can see. The first job is an inventory: for each event type, which module publishes it, which listeners consume it, whether each listener is synchronous, asynchronous or transactional, and whether it has an @Order. Spring Modulith makes this much cheaper than reading code by hand. ApplicationModules.of(App.class) builds a model of the modules from the package structure, and its Documenter writes diagrams of module dependencies and per-module canvases that list the events each module publishes and listens to.
In a real codebase the first output is often humbling: a dependency cycle between two modules, an event listened to by seven modules, a module that both publishes and listens to its own events in a loop. That picture is the agenda for the rest of the work, and sharing it with the teams turns a vague complaint into a list of specific problems.
2Turn Events Into Owned Contracts
Many tangled event systems share one root cause: events are whatever classes happened to be handy, often JPA entities or classes placed in a common package that everyone edits. The fix is ownership. Each cross-module event becomes a record in the publishing module's public API package, carrying the facts a listener needs, such as ids, amounts and timestamps, and nothing internal. The publishing team owns its shape.
Owned contracts also need a change rule. Adding an optional field is safe. Renaming or removing a field, or changing its meaning, is a breaking change and gets a new version, for example OrderPlacedV2 published alongside the old one until listeners have moved. This is the same discipline we would need with a broker, and building it now makes a later split much cheaper.
3Remove Reliance on Listener Order
Implicit ordering is the most dangerous kind of hidden coupling, because it breaks silently when someone adds @Async or a new listener. During the inventory, every @Order on a cross-module listener, and every listener that reads data another listener writes, is a candidate. For each, we ask whether the listeners are really independent reactions or steps of one process.
If they are steps, the flow is a workflow and should be orchestrated explicitly: one component, usually in the module that owns the process, calls the steps in order through public interfaces, or each step publishes a completion event that the next step listens to. Either way the order is visible in code and survives threading changes.
- Does it depend on another listener's work?YesMake the flow an explicit workflowNoKeep it as an event reaction
- Must it not be lost on a crash?YesUse the publication registry or an outboxNoIn-memory delivery is fine
- Does it read another module's internals?YesExpose the data through the event or an APINoBoundary is clean
- Add a Scenario testthe module publishes and reacts as documented
4 steps in order. Play them, or step through them one at a time.
4Decide Reliability Per Event
Not every event needs the same delivery guarantee. For each event and listener we decide whether losing it on a crash or deploy is acceptable. Where it is not, the listener becomes a transactional listener backed by Spring Modulith's event publication registry, or the event goes through an outbox, so an incomplete delivery is recorded and can be retried. Where it is acceptable, plain in-memory delivery stays, and the decision is written down next to the listener so the next developer does not have to guess.
5Lock It In With Tests
Finally, we make the agreed structure a build check. A verification test fails when one module uses another's internal types or when a dependency cycle appears. Module integration tests check that each module publishes and reacts to events as its contract says. Spring Modulith's @ApplicationModuleTest boots one module alone, and its Scenario API drives a stimulus and waits for an expected event.
These tests protect the work from slow erosion. A new listener that reaches into another module, or a refactoring that stops publishing an event a contract promises, fails in CI rather than in production. Check your Modulith version for the exact Scenario method names.
6Follow-up questions
When would you instead replace an event with a direct method call?
When the publisher actually needs the result, or must fail if the reaction fails. For example, if placing an order must reserve stock and refuse the order when stock is short, that is a request, and a call through the inventory module's public interface states it honestly. Events suit facts others may react to without the publisher caring how; when the publisher cares, a call is the clearer design.
How do you get teams to adopt contracts without stopping feature work?
Start with the events involved in recent incidents and the ones with the most listeners, since those give the most value. Add the verification test in a reporting mode first, listing violations without failing, then switch it to failing once the known violations are fixed, so new ones cannot appear.
Does all this make events too heavy to use?
It makes cross-module events deliberate, which is the goal. Events inside one module can stay informal. The extra work is mostly one-time: an owned record, a decision about reliability and one scenario test per contract.
7Conclusion
In this answer, we brought tangled module events under control without banning them. We made flows visible with an inventory and Spring Modulith's documentation, turned cross-module events into versioned contracts owned by the publisher, replaced reliance on listener order with explicitly orchestrated workflows, chose reliable delivery through a publication registry or outbox where losing an event is unacceptable, and locked the structure in with boundary verification and Scenario tests.
Open with
I would not ban events, because the decoupling they give is real, but I would make them deliberate. First, visibility: I would inventory every event and listener, and use Spring Modulith's model and documenter to produce the module dependency diagram and the list of events each module publishes and consumes.
Then, if they want more
That usually reveals cycles and events with far too many consumers, and it gives the teams a shared agenda. Second, contracts: every cross-module event becomes a small record in the publishing module's public API, owned by that team, with a rule that breaking changes get a new version.
Third, ordering: any listener that relies on running before or after another is a sign that the flow is really a workflow, so I would make it explicit, either one orchestrating component calling the steps or each step publishing a completion event the next one listens to.
Fourth, reliability: per event, we decide whether losing it on a crash is acceptable, and where it is not, we use Modulith's event publication registry or an outbox. Finally, tests: a verification test that fails on internal access or cycles, and module tests with Modulith's Scenario API that check each module publishes what its contract promises.
And where a module actually needs the result, I would replace the event with a direct call through a public interface.
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 Framework reference, Core technologies
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 "In a modular monolith, events between modules have grown to dozens of listeners with...": https://scrivio-interview-library.netlify.app/spring-boot/spring-events/e13347aaf5/