Spring Boot & Microservices (50 Qs)•Part 3: Microservices, Distributed Systems & Observability (25 - 35)
Transactional Application Events: `@TransactionalEventListener`.
senior LevelSystem DesignDatabases & SQLMicroservices
In Simple Words:
Standard Spring @EventListener executes immediately when the event is published, even if the database transaction later rolls back!
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT): Guarantees the listener executes only after the database transaction has successfully committed, preventing sending emails or Kafka messages for orders that rolled back!