Back to feed
Dev.to
Dev.to
6/24/2026
Your @EventListener Fires Before the Transaction Commits⚙️

Your @EventListener Fires Before the Transaction Commits⚙️

Short summary

Spring's @EventListener fires mid-transaction before commit, causing stale reads. @TransactionalEventListener(AFTER_COMMIT) prevents stale reads but can silently drop events on listener failure. For mission-critical events, use the outbox pattern to guarantee reliable delivery tied to the database transaction.

  • @EventListener fires before commit; other DB connections see stale state until transaction completes
  • @TransactionalEventListener(AFTER_COMMIT) fixes visibility but loses events if the listener fails post-commit
  • Outbox pattern ensures reliable event delivery by writing events to the database within the same transaction

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more