Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Code reviews show REQUIRES_NEW used widely to 'make sure things get saved'. What problems does this cause at scale, and what alternatives would you recommend as a standard?

Used widely, REQUIRES_NEW makes every request hold two connections at once, which exhausts connection pools and can deadlock them under load. It also splits one use case into independent commits that leave partial results behind after failures, and an inner transaction can block forever on a lock held by its own suspended outer transaction. As a standard, I would recommend one transaction per use case, after-commit events or an outbox for side effects, separate jobs for side records, and REQUIRES_NEW only for documented cases such as audit or idempotency records.

Why this question is asked

'Make sure it gets saved' is an understandable instinct: someone saw a record disappear after a rollback, added REQUIRES_NEW, and the record stayed. Copied across a codebase, though, that fix turns into one of the more dangerous patterns in Spring applications, because its costs are invisible in tests and only appear under concurrency and failure. Interviewers ask this design question to see whether we can explain those costs concretely and replace a habit with a standard. In this answer, we will see what REQUIRES_NEW really does, then go through the three problems, pool exhaustion, partial commits and self-deadlock, and finish with the alternatives and the rule for when REQUIRES_NEW is allowed.

1What REQUIRES_NEW Actually Does

When a method with REQUIRES_NEW is called inside an existing transaction, Spring suspends the existing one: it unbinds its connection and EntityManager from the thread and keeps them aside. Then it takes a new connection from the pool and starts a fresh transaction, which commits or rolls back on its own. When the method returns, Spring resumes the suspended transaction.

The important detail is that suspended does not mean released. The outer transaction still owns its connection, its open locks and its uncommitted changes the whole time the inner one runs.

2Problem 1: Two Connections Per Request and Pool Deadlocks

Every request that passes through a REQUIRES_NEW method holds two connections at the same moment. If the pattern is nested, say a service calls one REQUIRES_NEW method that calls another, it is three. The pool has to be sized for the worst path, not the average one.

The failure under load is a pool deadlock. Take a HikariCP pool of 10 and 10 concurrent requests. Each request starts its outer transaction and takes one connection; now the pool is empty. Each then reaches a REQUIRES_NEW method and asks for a second connection. None will ever be returned, because each connection is held by a request waiting for another one. After connectionTimeout, 30 seconds by default, all 10 requests fail, and in the meantime every other request in the service is blocked too.

Java
// HikariCP log under load:
// HikariPool-1 - Connection is not available, request timed out after 30000ms
// (total=10, active=10, idle=0, waiting=37)
// java.sql.SQLTransientConnectionException
Step throughA pool of 2 with 2 concurrent requests
Request APool (2 connections)Request B
outer tx: take connection 1
outer tx: take connection 2
REQUIRES_NEW: need another, wait
REQUIRES_NEW: need another, wait
timeout after 30 s
timeout after 30 s

6 messages in order. Play them, or step through them one at a time.

Both requests hold what the other needs; nobody can finish.

3Problem 2: One Use Case, Many Independent Commits

Each REQUIRES_NEW method commits on its own. So a use case like 'place order' that saves the order in the outer transaction, but writes the invoice, the loyalty points and the notification record in REQUIRES_NEW methods, is really four transactions. If the outer transaction fails at the end, for example on a constraint at flush, the invoice, points and notification rows stay committed for an order that does not exist.

Those partial results are the opposite of what the developer wanted. 'Make sure it gets saved' became 'make sure it gets saved even when it should not be'. Finding and cleaning these orphan rows later is expensive, and they often cause customer-facing errors, such as an invoice for a cancelled order.

4Problem 3: Blocking on Your Own Locks

The inner transaction runs on a different connection, so the database sees it as a completely different transaction. If the outer transaction has updated a row and the inner one tries to update or lock the same row, the inner one waits for the outer one to commit. But the outer one is suspended, waiting for the inner one to return. Neither can move.

Java
@Transactional
public void close(long accountId) {
Account a = accounts.findById(accountId).orElseThrow();
a.setStatus(CLOSED);
accounts.flush(); // UPDATE account 7: row lock held
history.recordStatus(accountId); // REQUIRES_NEW on another bean
}
// recordStatus(): UPDATE account SET last_event = now() WHERE id = 7
// -- waits for the outer transaction's lock, which waits for recordStatus() to return
// -- the database cannot see it as a deadlock: it ends only at a lock or statement timeout

The database's deadlock detector cannot help, because from its point of view one transaction is simply waiting for another that is idle. The request hangs until a lock timeout or statement timeout fires, if one is configured.

5Alternatives to Recommend as a Standard

The standard starts from one transaction per use case: everything the use case writes commits or rolls back together. Most 'make sure it gets saved' cases disappear once the real cause of the rollback is fixed.

For work that should happen only if the use case succeeds, such as sending a notification, use an after-commit event (@TransactionalEventListener with phase AFTER_COMMIT) or, when it must not be lost, an outbox row written in the same transaction and processed afterwards. For side records that can be built later, such as statistics or search indexes, use separate jobs that read committed data.

REQUIRES_NEW remains allowed for a short list of documented cases where a write must survive the outer rollback by design: an audit record of an attempt, or an idempotency record that marks a request as received. Each use is short, never called in a loop, never touches rows the outer transaction holds, and the pool is sized for it.

Replacing REQUIRES_NEW
NeedStandard approach
Part of the same business operationSame transaction (REQUIRED)
React only if the operation commits@TransactionalEventListener AFTER_COMMIT
Must happen reliably after commitOutbox row in the same transaction
Derived data such as stats or indexesSeparate job on committed data
Must survive a rollback (audit, idempotency)REQUIRES_NEW, documented and short

6Rolling Out the Standard

I would start by finding every REQUIRES_NEW, which is easy with a search or an ArchUnit rule that lists them, and asking for each one which of the needs in the table it serves. Many turn out to hide a different bug, such as a swallowed exception that marked the transaction rollback-only. Then add the rule to the review checklist, allow new uses only with a comment that names the reason, and add a load test with a deliberately small pool, which reveals pool deadlocks within minutes instead of in production.

7Follow-up questions

How do you size the pool if REQUIRES_NEW is needed?

For the peak number of concurrent requests on that path times the connections each holds at once, plus headroom for other traffic. A common safeguard is a separate small pool, or a separate DataSource, for the audit writes, so they can never starve the main pool.

Does NOT_SUPPORTED have the same pool problem?

Partly. It also suspends the outer transaction and keeps its connection, and if the code inside it uses the database it takes a second connection with autocommit. So the same sizing concern applies.

How would you detect self-deadlocks in production?

Through lock wait monitoring in the database, for example pg_stat_activity showing a session waiting on a lock held by an idle-in-transaction session from the same application, and by setting lock_timeout or statement timeouts so such waits fail quickly and get logged.

8Conclusion

In this answer, we saw that REQUIRES_NEW suspends the outer transaction without releasing its connection, so wide use doubles connections per request and can deadlock the pool, splits a use case into independent commits that leave partial results, and can make an inner transaction wait on its own outer transaction's locks. As a standard we use one transaction per use case, after-commit events, an outbox or separate jobs, and keep REQUIRES_NEW for short, documented audit and idempotency cases.

What to say in the interviewAbout 100 seconds aloud

Open with

The first problem is connections. REQUIRES_NEW suspends the outer transaction, but the outer transaction keeps its connection, so every request on that path holds two connections. Under load that becomes a pool deadlock: with a pool of 10 and 10 concurrent requests, each holds one connection and waits for a second, nobody can finish, and after HikariCP's 30-second timeout they all fail, along with everything else using the pool.

Then, if they want more

The second problem is consistency. Each REQUIRES_NEW commits on its own, so one use case becomes several transactions, and if the outer one fails at the end you're left with invoices or points for an order that doesn't exist.

The third is self-blocking: if the outer transaction has locked a row and the inner one touches it, the inner waits for the outer, the outer waits for the inner, and the database can't detect it as a deadlock, so it hangs until a timeout. As a standard, I'd say one transaction per use case by default.

If something should only happen after success, use a TransactionalEventListener after commit, or an outbox when it mustn't be lost. Derived records go to separate jobs. REQUIRES_NEW is allowed only for documented cases like an audit of an attempt or an idempotency record, kept short and never in a loop.

I'd review the existing uses one by one, because many are hiding a different bug, and add a load test with a small pool.

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.
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 "Code reviews show REQUIRES_NEW used widely to 'make sure things get saved'. What...": https://scrivio-interview-library.netlify.app/databases/transactions/9b1d453b5a/