Member-only story
You Don’t Need @Transactional Everywhere in Spring Boot — Here’s Why
3 min readMay 12, 2025
Using @Transactional
everywhere in a Spring Boot application is a common anti-pattern. While transactions are essential for ensuring data consistency and rollback behavior, overusing @Transactional
can lead to performance issues, unexpected behavior, and unnecessary complexity.
Here’s a breakdown of when you should and shouldn’t use @Transactional
:
🚫 The Problem: Overusing @Transactional
Many developers tend to annotate every service method with @Transactional
, assuming it’s necessary for anything involving the database.
But in reality:
- It adds unnecessary overhead.
- It can cause confusion about transaction boundaries.
- It may hide design issues, like mixing read and write concerns.
✅ When You Should Use @Transactional
- Multiple Write Operations on the Database
- When you have more than one
INSERT
,UPDATE
, orDELETE
that should succeed or fail together. If you’re performing multiple operations that need to succeed or fail together, use@Transactional
.
@Transactional
public void transferMoney(Long fromAccountId, Long toAccountId, BigDecimal amount) {
accountRepository.debit(fromAccountId, amount);
accountRepository.credit(toAccountId, amount);
}