Skip to content

feat: decouple email delivery with application events, asynchronous execution, and Resilience4j retries - #39

Merged
podlLev merged 7 commits into
devfrom
fix/async-mail-dispatch
Jul 27, 2026
Merged

podlLev merged 7 commits into
devfrom
fix/async-mail-dispatch

Conversation

@podlLev

@podlLev podlLev commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Overview

This PR refactors the notification delivery layer by decoupling mail operations from HTTP request threads using Spring Application Events and asynchronous processing. It also adds Resilience4j fault tolerance to handle transient SMTP delivery failures without blocking client workflows.


Key Changes

  • Event-Driven Architecture & Decoupling:

    • Application Events: Introduced VerificationEmailRequestedEvent and PasswordResetEmailRequestedEvent domain events to represent mail requests cleanly.
    • Event Publisher: Refactored business services to dispatch events rather than calling MailService directly, eliminating tight coupling.
  • Asynchronous Execution & Resilience:

    • Transaction-Aware Async Processing: Created MailEventListener to handle mail dispatch asynchronously post-transaction commit (@TransactionalEventListener), preventing email delivery latency from delaying HTTP responses.
    • ThreadPool Configuration: Configured a dedicated mailTaskExecutor bean and enabled @Async support for isolated concurrency management.
    • SMTP Fault Tolerance: Integrated Resilience4j retry mechanisms into the mail delivery pipeline to automatically recover from transient SMTP errors.
  • Test Suite Updates:

    • Unit & Integration Tests: Updated MailServiceImplTest and VerificationServiceImplTest to reflect event publication logic and added MailEventListenerTest to cover event listener behavior and retries.

@podlLev podlLev self-assigned this Jul 27, 2026
@podlLev podlLev added fix A bug fix or patch resolving a runtime error or misbehavior performance Optimization changes (e.g., lazy loading, caching, SQL tuning) labels Jul 27, 2026
@podlLev
podlLev merged commit 6d50d3b into dev Jul 27, 2026
2 checks passed
@podlLev
podlLev deleted the fix/async-mail-dispatch branch July 27, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix or patch resolving a runtime error or misbehavior performance Optimization changes (e.g., lazy loading, caching, SQL tuning)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant