Thu. Apr 16th, 2026

How to Reliably Implement Post-Commit Actions in Spring


Sometimes, in modern backend systems, you need to perform one or more actions after database inserts or updates. You may need to publish to a message broker, send an email, or trigger a workflow. If you perform those actions inside a database transaction that rolls back at the end, it is too late, because they are already started and cannot be cancelled, possibly creating inconsistencies. In Spring Boot, you can use @TransactionalEventListener to mark a listener that is triggered by the ApplicationEventPublisher’s publish method to solve this problem. In this article, we will explain how this works.

The Problem

In this article, we are discussing the side effects associated with transactional code.  By side effects, we mean deliberate actions towards external services and resources. As an example, we can consider an application component that creates an order, saves it in the database, and then sends an email:

By uttu

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *