Quick revision
The short answer
In-process events are a good fit when the listeners live in the same service and losing a side effect now and then is acceptable: they are cheap and keep modules decoupled at compile time. They give no durability, retry or replay, so anything that must happen after a commit belongs in a transactional outbox or an event publication registry such as Spring Modulith's, and anything consumed by another service needs a broker. Either way, we keep event types as explicit, stable contracts so moving later is easy.
What to remember
In this answer, we saw that in-process Spring events are cheap and decouple modules at compile time, but they live only in memory, so a crash or deploy loses them and failed listeners have no retry or replay. We chose a mechanism per side effect: in-process events for best-effort work such as analytics, an outbox or Spring Modulith's publication registry for side effects that must happen after commit, and a broker fed by an outbox for consumers in other services. Keeping events as small, stable records makes that later move a change of transport only.
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.
In-process events are a good fit when the listeners live in the same service and losing a side effect now and then is acceptable: they are cheap and keep modules decoupled at compile time. They give no durability, retry or replay, so anything that must happen after a commit belongs in a transactional outbox or an event publication registry such as Spring Modulith's, and anything consumed by another service needs a broker. Either way, we keep event types as explicit, stable contracts so moving later is easy.
Why this question is asked
Using events to decouple an order module from email, analytics and loyalty is a sensible design, and it usually starts with Spring's in-process events because they need no infrastructure. The trouble starts when the team assumes these events behave like messages on a broker. Interviewers ask this design question to see whether we know what in-process events promise, and what they do not. In this answer, we will recap what an in-process event is, walk through the failure cases, decide for each of the three modules which mechanism fits, look at the outbox and the Modulith registry, and see how to keep the events ready for a later move.
1What an In-Process Event Really Is
When the order module calls publishEvent(new OrderPlaced(id)), Spring passes the object to the listeners in the same JVM. With a plain @EventListener the call is synchronous; with @TransactionalEventListener it is delayed until the order transaction commits; with @Async it runs on a thread pool. In every case the event exists only in memory. Nothing is written anywhere.
That is why they are attractive. There is no broker to run, no serialisation, and delivery takes microseconds. The order module depends only on the event type, not on the email, analytics or loyalty code, so those modules can change without touching orders. That compile-time decoupling is the real value.
2Where In-Process Events Lose Work
Because the event is only in memory, any moment when the JVM stops loses it. Suppose the order transaction commits and an AFTER_COMMIT listener is about to send the confirmation email. If the pod is killed by a deploy at that moment, the order exists but no email is ever sent, and nothing records that it was missed.
Failures inside a listener are just as quiet. If the loyalty service is down and the listener throws, an AFTER_COMMIT listener's exception is logged and the event is gone. There is no retry, no dead letter queue, and no way to replay last Tuesday's events after fixing a bug. With a synchronous listener the failure is worse in the other direction: it propagates into the order code and can roll back the order.
4 messages in order. Play them, or step through them one at a time.
The order is committed, the email is never sent, and nothing records the loss.
3Deciding Per Side Effect
The right answer is not one mechanism for everything; it is a decision per listener based on what losing it costs. Analytics can usually tolerate the occasional lost event, so an in-process @TransactionalEventListener, possibly @Async, is fine. A confirmation email is visible to customers, so we want it to happen reliably, but one service still handles it. Loyalty points are money, so they must happen exactly once in effect, and if loyalty is owned by another team's service, the event must cross a process boundary.
| Side effect | Cost of losing it | Mechanism |
|---|---|---|
| Analytics counter | low: a slightly wrong dashboard | in-process event, after commit |
| Confirmation email | medium: customer complaint | publication registry or outbox |
| Loyalty points in another service | high: money, another team | outbox relayed to a broker |
4The Outbox and the Event Publication Registry
A transactional outbox stores the event in the database in the same transaction as the business change. Either both the order and its event row commit, or neither does. A separate relay then reads unsent rows and delivers them, to a listener or to a broker, and marks them sent. If the JVM dies, the row is still there and the relay picks it up after restart.
Spring Modulith offers this pattern for in-process listeners through its event publication registry. When an event is published inside a transaction, the registry writes one entry per transactional listener that will receive it, in the same transaction. When that listener finishes successfully, the entry is marked complete. Entries that never complete, because of a crash or an exception, stay incomplete and can be resubmitted, for example on restart if we enable that option.
Notice the consequence: delivery is now at least once. If the email was sent but the JVM died before the entry was marked complete, it is sent again after restart. So listeners behind a registry or outbox must be idempotent, meaning that handling the same event twice has the same effect as handling it once, for example by recording processed order ids.
5When a Broker Is Required
In-process events cannot reach another deployment. The moment loyalty runs as its own service, or a second instance of our service should share the work, we need a broker such as Kafka or RabbitMQ. The outbox remains the safe way to get the event there: write the row with the order, and let a relay, a polling publisher, change data capture with Debezium, or Modulith's event externalization, send it to the broker. Publishing straight to Kafka from an AFTER_COMMIT listener reintroduces the same gap we saw above.
6Keeping Events as Contracts
Even inside one service, we treat each event type as a contract owned by the publishing module: a small record with the facts that happened, such as the order id, the customer id and the total, not a reference to a mutable entity. We avoid putting the JPA Order entity itself in the event, because listeners would then depend on its internals and lazy loading. A stable record can later be serialised to JSON and put on a broker unchanged, so extracting a module into a service changes the transport, not every listener.
7Follow-up questions
What does Spring Modulith's event publication registry store, and when is an entry marked complete?
For each event published in a transaction and each transactional listener that will receive it, the registry stores an entry with the serialised event, its type, an identifier for the listener and the publication time. The entry is written in the publisher's transaction. It is marked complete, with a completion time, when that listener finishes without an exception. Incomplete entries can be inspected and resubmitted, and completed ones can be deleted or archived depending on the configuration; check your Modulith version for the exact options.
Can't we just retry inside the listener?
A retry inside the listener helps with short outages, but it still lives in memory. If the JVM stops during the retries, the work is lost. Durable storage before the side effect is the only way to survive a crash.
Does using events make the order module unaware of the others?
At compile time, yes. At runtime it still depends on them in a hidden way, because a synchronous listener's slowness or failure affects the order. That is why choosing after-commit or asynchronous delivery is part of the design, not an afterthought.
8Conclusion
In this answer, we saw that in-process Spring events are cheap and decouple modules at compile time, but they live only in memory, so a crash or deploy loses them and failed listeners have no retry or replay. We chose a mechanism per side effect: in-process events for best-effort work such as analytics, an outbox or Spring Modulith's publication registry for side effects that must happen after commit, and a broker fed by an outbox for consumers in other services. Keeping events as small, stable records makes that later move a change of transport only.
Open with
In-process events are a good fit when the listeners are in the same service and losing an occasional side effect is acceptable. They are cheap, need no infrastructure, and the order module depends only on the event type, not on email, analytics or loyalty code.
Then, if they want more
But they live only in memory. If the JVM dies after the order commits and before an after-commit listener runs, the side effect is lost and nothing records it, and a failed listener has no retry or replay; it is just a logged exception. So I would decide per side effect. Analytics can stay a plain after-commit event.
The confirmation email must happen, so I would use a transactional outbox or Spring Modulith's event publication registry, which writes an entry per listener in the same transaction as the order and marks it complete when the listener succeeds, so incomplete ones can be resubmitted after a crash. That gives at-least-once delivery, so the listener must be idempotent.
Loyalty, if it is another service, needs a broker, and I would feed the broker from the outbox, not from an after-commit listener, so there is no gap. In all cases I keep events as small, stable records owned by the publishing module, so moving one to a broker later only changes the transport.
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 "A team uses application events to decouple an order module from email, analytics and...": https://scrivio-interview-library.netlify.app/spring-boot/spring-events/67109a37b4/