Skip to content

feat: convert audit logging to asynchronous using Spring @Async #1327

@iRahmanG

Description

@iRahmanG

Problem

Currently, AuditService.log() and logCaseAction() call repository.save(log) synchronously.
This blocks the request thread until the database write completes, which slows down case operations under heavy load.

Proposed Improvement

  • Replace the existing synchronous methods with asynchronous ones by annotating them with @Async.
  • Keep the same method names (log, logCaseAction) to avoid duplication and confusion.
  • Ensure @EnableAsync is already active in the main application class (confirmed).
  • Controller calls remain unchanged, but logging will now run in a background thread.

Impact

  • Performance: Faster API responses since logging is offloaded.
  • Scalability: Handles higher logging volume without blocking request threads.
  • Clean design: No duplicate methods; existing service methods simply become async.

Steps to Implement

  1. Add @Async annotation to AuditService.log() and logCaseAction().
  2. Verify that @EnableAsync is present in the main application class.
  3. Test by firing multiple concurrent requests and confirming logs are persisted correctly.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions