Quick revision
The short answer
The event publication registry stores each event publication for each transactional listener in a database table, inside the publisher's transaction, and marks it complete when the listener succeeds. @ApplicationModuleListener is an asynchronous @TransactionalEventListener that runs after commit in its own transaction, so if it fails or the application crashes, the publication stays incomplete and can be resubmitted on restart or through IncompleteEventPublications; listeners must therefore be idempotent. Completed entries should be cleaned up, and @Externalized event types are published to Kafka through the same registry, giving an outbox-like pattern without a hand-written relay.
What to remember
In this answer, we saw that @ApplicationModuleListener is an async transactional listener that runs after commit in its own transaction, and that the event publication registry records each publication in the publisher's transaction and marks it complete on success. Failures and crashes leave incomplete publications that are resubmitted on restart or through IncompleteEventPublications, so listeners must be idempotent. We clean completed entries with CompletedEventPublications or a completion mode, and @Externalized events reach Kafka through the same mechanism, giving an outbox-like pattern.
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.
The event publication registry stores each event publication for each transactional listener in a database table, inside the publisher's transaction, and marks it complete when the listener succeeds. @ApplicationModuleListener is an asynchronous @TransactionalEventListener that runs after commit in its own transaction, so if it fails or the application crashes, the publication stays incomplete and can be resubmitted on restart or through IncompleteEventPublications; listeners must therefore be idempotent. Completed entries should be cleaned up, and @Externalized event types are published to Kafka through the same registry, giving an outbox-like pattern without a hand-written relay.
Why this question is asked
Splitting an application into modules that communicate with events is one of Spring Modulith's main ideas. But in-memory events have a weakness: if the listener fails, or the process dies after the database commit, the event is gone and the other module never hears about it. The event publication registry closes that gap. Interviewers ask about it to see whether we understand delivery guarantees, transaction boundaries and what happens in failure cases. In this answer, we will recap how @ApplicationModuleListener runs, follow a publication through the registry, look at failure and crash recovery, clean up completed entries, and externalize events to Kafka.
1A Quick Recap of @ApplicationModuleListener
In Spring, we publish an event with ApplicationEventPublisher.publishEvent, and listeners receive it. A @TransactionalEventListener delays delivery until a transaction phase, by default after commit, so listeners only react to changes that were really saved.
@ApplicationModuleListener combines three annotations: @Async, so the listener runs on another thread; @Transactional with REQUIRES_NEW propagation, so it runs in its own new transaction; and @TransactionalEventListener, so it runs after the publisher's transaction commits. The result is that the orders module can complete an order and return quickly, while the inventory module reacts later in its own transaction.
But there is a catch. Without anything else, the event lives only in memory between the commit and the listener's run. If the listener throws, or the JVM stops in that window, the event is lost.
2Following a Publication Through the Registry
When we add a registry starter, such as spring-modulith-starter-jpa or spring-modulith-starter-jdbc, Spring Modulith intercepts event publication. For each transactional listener that will receive the event, it writes a row to the event publication table, inside the publisher's transaction. So the order change and the record of the pending event commit together, or not at all.
After the commit, the listener runs asynchronously. When it returns successfully, the registry marks that publication as complete by setting its completion date. If it throws, the row stays incomplete.
6 messages in order. Play them, or step through them one at a time.
If the listener throws or the process dies before the last step, the row stays incomplete.
3When the Listener Fails or the Application Crashes
In both failure cases, the database holds the truth: an incomplete publication with the listener's id and the serialized event. Spring Modulith gives two ways to deliver it again. On startup, if republishing outstanding events on restart is enabled, through a property such as spring.modulith.events.republish-outstanding-events-on-restart, the registry resubmits all incomplete publications. While running, we can inject IncompleteEventPublications and resubmit publications older than a given age, for example from a scheduled job.
Notice what this means for listeners: delivery is at least once. A listener may have done its work and then failed to mark completion, or a resubmission may race with a slow first attempt, so the same event can arrive twice. Listeners must be idempotent, for example by checking whether stock for that order was already released, or by using a unique constraint on the effect they write. The property names and some method names have changed between versions, so check the reference documentation for yours.
4Cleaning Up Completed Publications
By default, completed publications stay in the table with their completion date. Over months, a busy application accumulates millions of rows. We can delete old completed entries with CompletedEventPublications, for example deletePublicationsOlderThan(Duration.ofDays(7)) from a scheduled job. Recent versions also offer a completion mode setting that deletes or archives a publication as soon as it completes, instead of updating it; check your version for the property name and the options it supports.
Keeping the table small matters for more than disk space. Resubmission and monitoring queries scan incomplete rows, and a small table keeps them fast.
5Externalizing Events to Kafka
Other services cannot see in-process events. Spring Modulith can publish selected event types to a broker. We annotate the event type with @Externalized, naming the target topic and optionally a key expression, and add the Kafka externalization module, spring-modulith-events-kafka, or the AMQP one. Spring Modulith then registers an internal transactional listener that sends matching events with Spring's KafkaTemplate.
Because that externalization listener is itself tracked by the registry, the send is recorded in the publisher's transaction and retried if Kafka is unavailable, exactly like a module listener. That gives us an outbox-like pattern: the database change and the intent to publish commit together, and delivery happens afterwards, at least once, without writing our own relay that polls an outbox table.
6Follow-up questions
How is this different from a classic outbox with Debezium?
Both write the event in the same transaction as the business change. With Debezium, a separate change data capture process reads the database's transaction log and publishes outbox rows to Kafka, so delivery does not depend on our application being up, and ordering follows the log order. It needs Kafka Connect and Debezium infrastructure to run and monitor. Spring Modulith's externalization runs inside the application after commit, needs no extra infrastructure, and retries through the registry, but delivery happens only while the application runs, and ordering across retries is not guaranteed. For most module events and moderate volumes, the in-process approach is simpler; for strict ordering, very high volume or many producing applications, Debezium is often the better fit.
Does the registry work without a transaction?
It is designed for transactional event listeners, which only fire when there is a transaction to bind to. If the event is published outside a transaction, transactional listeners do not run by default, so there is nothing to register. Publish module events from transactional service methods.
Which database tables does it use?
The JPA and JDBC starters use an event publication table, which the JDBC module can create through a schema initialisation property or which we create with Flyway or Liquibase from the scripts the project ships. The columns have changed between major versions, so use the scripts for your version.
7Conclusion
In this answer, we saw that @ApplicationModuleListener is an async transactional listener that runs after commit in its own transaction, and that the event publication registry records each publication in the publisher's transaction and marks it complete on success. Failures and crashes leave incomplete publications that are resubmitted on restart or through IncompleteEventPublications, so listeners must be idempotent. We clean completed entries with CompletedEventPublications or a completion mode, and @Externalized events reach Kafka through the same mechanism, giving an outbox-like pattern.
Open with
@ApplicationModuleListener is shorthand for @Async, @Transactional with REQUIRES_NEW and @TransactionalEventListener, so it runs after the publisher commits, on another thread, in its own transaction. On its own that leaves a gap: if the listener fails or the JVM dies after commit, the in-memory event is lost.
Then, if they want more
The event publication registry closes it. With the JPA or JDBC starter, when an event is published, Modulith inserts one row per transactional listener into the event publication table inside the publisher's transaction, so the business change and the pending event commit together. When the listener succeeds, the row is marked complete.
If it fails or the app crashes, the row stays incomplete, and I can resubmit it on restart with the republish-outstanding-events setting, or at runtime with IncompleteEventPublications, for example resubmitting publications older than five minutes from a scheduled job. That makes delivery at least once, so listeners must be idempotent.
Completed rows should be cleaned up with CompletedEventPublications or a completion mode that deletes or archives them, depending on the version. For other services, I annotate the event with @Externalized and add the Kafka module; the send goes through the registry too, so I get an outbox-like pattern without writing a relay.
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 "Explain Spring Modulith's event publication registry. What happens when an...": https://scrivio-interview-library.netlify.app/spring-boot/spring-projects/ec49431d8e/