Quick revision
The short answer
@Async listeners keep their pending work in an in-memory executor queue, so every shutdown, deploy or crash discards whatever has not run yet. The standard I would set is that side effects that must happen are persisted first, through an outbox or an event publication registry, and processed by a broker or job queue that survives restarts. @Async listeners stay allowed only for documented best-effort work, and every executor waits for running tasks on shutdown with a bounded timeout.
What to remember
In this answer, we saw that @Async listeners keep pending work in an in-memory queue, so deploys and crashes drop it. The standard classifies each side effect: must-happen work is persisted first through an outbox or event publication registry and processed from a broker, job queue or registry with idempotent handlers, while @Async stays for documented best-effort work, with graceful shutdown that waits a bounded time and executors that are bounded and monitored.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@Async listeners keep their pending work in an in-memory executor queue, so every shutdown, deploy or crash discards whatever has not run yet. The standard I would set is that side effects that must happen are persisted first, through an outbox or an event publication registry, and processed by a broker or job queue that survives restarts. @Async listeners stay allowed only for documented best-effort work, and every executor waits for running tasks on shutdown with a bounded timeout.
Why this question is asked
Losing a few emails or search index updates on each deploy is easy to ignore at first, because each loss is small and nobody is paged. Over months it becomes customers who never got a receipt and search results that are quietly wrong. Interviewers ask this design question to see whether we can find the common cause across services and set a rule that fixes it without banning a useful tool. In this answer, we will see exactly where the work is lost, separate work that must happen from best-effort work, design the durable path, set up graceful shutdown for what stays in memory, and write the standard down.
1Where the Work Is Lost
An @Async listener does not run when the event is published. Spring wraps the call in a task and puts it on the queue of a ThreadPoolTaskExecutor, and a worker thread runs it later. Under load, that queue can hold hundreds or thousands of tasks. The queue exists only in the JVM's heap.
During a rolling deploy, Kubernetes sends SIGTERM to the old pod, Spring closes the application context, and the executor is shut down. By default, Spring's executor does not wait for queued tasks: they are dropped, and running tasks may be interrupted. A crash is worse, since nothing gets a chance to finish. Either way, the order was committed and its email or indexing task is gone, with no record that it existed.
5 messages in order. Play them, or step through them one at a time.
Committed orders whose side effects were still queued simply never get them.
2Must-Happen Work and Best-Effort Work
The first step of the standard is to classify each side effect. Must-happen work is anything a customer or another system relies on: a receipt email, a payment notification, an index update that search results depend on, a message to another team's service. Best-effort work is anything whose occasional loss is harmless or self-correcting: a cache warm-up, a usage metric, a notification that a later digest will repeat.
Teams tend to classify generously as best-effort, so the standard asks a concrete question: if this work were silently lost for one order in a thousand, would anyone need to fix it by hand? If yes, it is must-happen.
- Would a silent loss need manual repair?YesMust-happen workNoBest-effort work
- Must-happen: persist firstoutbox row or publication registry entry in the same transaction
- Process from durable storagebroker, job queue or registry resubmission, with retries
- Best-effort: @Async alloweddocumented as best-effort, graceful shutdown configured
4 steps in order. Play them, or step through them one at a time.
3Persisting First for Must-Happen Work
For must-happen work, the side effect is recorded durably in the same transaction as the business change, before anything is attempted. Within one Spring service, Spring Modulith's event publication registry does this for transactional listeners: it writes an entry per listener with the event, marks it complete when the listener succeeds, and can resubmit incomplete entries after a restart.
For work handled by other services, or work that must be retried with back-off for a long time, the outbox row is relayed to a broker such as Kafka or to a job queue, which keeps messages across restarts and redelivers them. In both cases delivery becomes at least once, so the handler must be idempotent: indexing the same order twice should give the same index, and sending a receipt should check whether it was already sent. Check your Modulith version for the exact property names and table layout.
4Graceful Shutdown for What Stays in Memory
Best-effort @Async work is still worth protecting during normal deploys, which are the most common cause of loss. Spring Boot can make the executor wait for its tasks on shutdown, up to a limit.
Notice the bounded timeout. Waiting forever would block deploys behind a stuck task, so we wait a fixed time and accept that a long backlog may still be cut off, which is acceptable only because this work is best-effort. The pod's grace period must be longer than Spring's waits, or Kubernetes kills the process before Spring finishes.
5Writing the Standard Down
The standard fits on one page. Every asynchronous side effect is classified as must-happen or best-effort in the code, for example with a comment or a naming convention. Must-happen work is persisted first and processed from durable storage, with idempotent handlers. @Async listeners are allowed only for best-effort work. Every executor has a bounded queue, graceful shutdown with a bounded wait, and metrics for queue size and rejections. A shared starter provides the registry or outbox setup and these defaults, so teams follow the standard by adding a dependency rather than reading a guide.
6Follow-up questions
Why not just make the executor wait for all tasks on shutdown?
Because it only helps planned shutdowns, and only if the backlog fits in the wait time. A crash, an out-of-memory kill or a node failure still loses everything queued. Waiting is a good addition for best-effort work, never a guarantee.
Is an outbox overkill for sending emails?
Not if the email matters, such as a receipt or a password reset. The cost is one insert in a transaction that already exists and a relay or registry that the shared starter provides. The alternative is an unknown number of missing emails per deploy.
How do you measure whether the standard is working?
Count the incomplete registry entries or unsent outbox rows over time and alert on their age, and compare business counts, for example orders placed against receipts sent per day. A gap between the two is lost work.
7Conclusion
In this answer, we saw that @Async listeners keep pending work in an in-memory queue, so deploys and crashes drop it. The standard classifies each side effect: must-happen work is persisted first through an outbox or event publication registry and processed from a broker, job queue or registry with idempotent handlers, while @Async stays for documented best-effort work, with graceful shutdown that waits a bounded time and executors that are bounded and monitored.
Open with
The cause is that @Async listeners put their work on an executor queue in memory. On every deploy, Spring shuts the executor down and by default queued tasks are simply dropped, and on a crash nothing finishes at all, so committed orders never get their email or index update and nothing records it.
Then, if they want more
The standard I would set starts with classification. If silently losing this work for one order in a thousand would need someone to fix it by hand, it is must-happen work; otherwise it is best-effort.
Must-happen work is persisted first, in the same transaction as the business change, either with an outbox table or Spring Modulith's event publication registry, and then processed from durable storage: a broker or job queue for work that crosses services or needs long retries, or registry resubmission after a restart within one service.
That gives at-least-once delivery, so handlers must be idempotent. @Async listeners stay allowed, but only for best-effort work, and that is documented in the code. For those, every service configures graceful shutdown with a bounded wait, using the spring.task.execution.shutdown properties, and a Kubernetes grace period longer than that wait. Every executor also has a bounded queue and metrics.
I would ship all of this as a shared starter, so following the standard is a dependency, not a document.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Several services use @Async event listeners for side effects such as emails and search...": https://scrivio-interview-library.netlify.app/spring-boot/spring-events/e41faace76/