spring-projects / spring-projects/spring-framework

Add support for batching event delivery in @EventListener and @TransactionalEventListener

Open
#35,681 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: data status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Description

Currently, Spring invokes @EventListener and @TransactionalEventListener methods once per published event. When multiple events of the same type are published within a single transaction, each results in a separate listener invocation.

It would be useful to support batched event delivery, allowing listeners to receive all events of the same type published during the transaction as a single List.

Use Case

Within a transactional service, multiple updates are performed, and corresponding domain events are published.
Each event triggers a separate listener call, resulting in multiple update statements and row locks.

Batch delivery would allow a single @TransactionalEventListener(phase = BEFORE_COMMIT) method to process all pending events together, enabling a single batched update.

Proposed Enhancement

Support for batched listener signatures such as:

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handleEvents(List<AppEvent> events) {
    batchUpdate(events);
}

The framework could accumulate events per transaction (e.g., using TransactionSynchronizationManager) and dispatch them together before commit.

Benefits

  1. Reduces redundant database updates
  2. Minimizes row locking and improves transaction efficiency
  3. Simplifies batching logic for domain event processing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @EventListener and @TransactionalEventListener handling described in the issue, then examine how TransactionSynchronizationManager could collect events during a transaction. Done means listeners accepting List can receive same-type events together, including BEFORE_COMMIT transactional delivery, while preserving existing single-event behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.