What is Propagation in Transactions?
Transaction Propagation in Spring Boot defines how transactions behave when one transactional method calls another transactional method.
In simple words:
βPropagation decides whether a method should join an existing transaction or create a new one.β
Why Transaction Propagation is Needed
Enterprise applications often contain:
- Nested service methods
- Multiple database operations
- Complex business workflows
Example:
- Order Service calls Payment Service
- Payment Service calls Notification Service
Spring must decide:
- Use same transaction?
- Create new transaction?
- Run without transaction?
Propagation controls this behavior.
Simple Real-Time Example
Suppose:
- OrderService.placeOrder()
- calls PaymentService.processPayment()
Questions:
- Should payment use same transaction?
- Should payment use separate transaction?
Propagation provides the answer.
How Propagation Works
Spring checks:
- Is transaction already running?
Then propagation rules decide:
- Join existing transaction
- Create new transaction
- Suspend transaction
Main Propagation Types in Spring Boot
| Propagation Type | Description |
|---|---|
| REQUIRED | Use existing transaction or create new |
| REQUIRES_NEW | Always create new transaction |
| SUPPORTS | Use transaction if available |
| NOT_SUPPORTED | Execute without transaction |
| MANDATORY | Must run inside existing transaction |
| NEVER | Must run without transaction |
| NESTED | Create nested transaction |
1. Propagation.REQUIRED
REQUIRED is the default propagation type in Spring Boot.
How REQUIRED Works
- If transaction exists β Join it
- If no transaction exists β Create new transaction
REQUIRED Example
@Transactional(
propagation = Propagation.REQUIRED
)
public void processPayment() {
}
REQUIRED Flow
Existing Transaction?
β
Yes β Join Existing
β
No β Create New
Real-Time Example
Order Service calls Payment Service.
Payment Service joins existing order transaction.
Advantages of REQUIRED
- Simple transaction management
- Efficient for related operations
- Most commonly used
2. Propagation.REQUIRES_NEW
REQUIRES_NEW always creates a completely new transaction.
How REQUIRES_NEW Works
- Suspends existing transaction
- Starts new transaction
REQUIRES_NEW Example
@Transactional(
propagation = Propagation.REQUIRES_NEW
)
public void saveAuditLog() {
}
REQUIRES_NEW Flow
Existing Transaction
β
Suspend Existing
β
Start New Transaction
β
Commit/Rollback
β
Resume Old Transaction
Real-Time Example
Suppose:
- Order transaction fails
- Audit logs still need saving
Use:
REQUIRES_NEW
Advantages of REQUIRES_NEW
- Independent transactions
- Useful for audit logging
- Useful for notifications
Disadvantages of REQUIRES_NEW
- Higher database overhead
- Additional transaction cost
3. Propagation.SUPPORTS
SUPPORTS uses transaction if available, otherwise runs without transaction.
SUPPORTS Example
@Transactional(
propagation = Propagation.SUPPORTS
)
public void getReports() {
}
SUPPORTS Flow
Transaction Exists?
β
Yes β Join Transaction
β
No β Execute Without Transaction
Best Use Case
- Read-only operations
- Reporting services
4. Propagation.NOT_SUPPORTED
NOT_SUPPORTED always executes without transaction.
How NOT_SUPPORTED Works
- Suspends existing transaction
- Runs method without transaction
NOT_SUPPORTED Example
@Transactional(
propagation = Propagation.NOT_SUPPORTED
)
public void generateLargeReport() {
}
Best Use Case
- Large reporting queries
- Non-transactional operations
5. Propagation.MANDATORY
MANDATORY requires an existing transaction.
How MANDATORY Works
- If transaction exists β Join it
- If no transaction exists β Exception occurs
MANDATORY Example
@Transactional(
propagation = Propagation.MANDATORY
)
public void updateBalance() {
}
Best Use Case
- Critical financial operations
6. Propagation.NEVER
NEVER must run without transaction.
How NEVER Works
- If transaction exists β Exception occurs
- If no transaction β Execute normally
NEVER Example
@Transactional(
propagation = Propagation.NEVER
)
public void exportFile() {
}
Best Use Case
- File operations
- External integrations
7. Propagation.NESTED
NESTED creates sub-transactions inside existing transaction.
How NESTED Works
- Creates savepoints
- Allows partial rollback
NESTED Example
@Transactional(
propagation = Propagation.NESTED
)
public void processSubTask() {
}
NESTED Flow
Main Transaction
β
Nested Transaction
β
Rollback Nested Only
Best Use Case
- Complex workflows
- Partial rollback support
Propagation Comparison Table
| Propagation | Existing Transaction | No Transaction |
|---|---|---|
| REQUIRED | Join | Create New |
| REQUIRES_NEW | Suspend & Create New | Create New |
| SUPPORTS | Join | No Transaction |
| NOT_SUPPORTED | Suspend | No Transaction |
| MANDATORY | Join | Exception |
| NEVER | Exception | No Transaction |
Real-Time Example in E-Commerce Application
Order placement process:
- Create order
- Process payment
- Save audit log
Recommended propagation:
- Order β REQUIRED
- Payment β REQUIRED
- Audit Log β REQUIRES_NEW
Advantages of Transaction Propagation
- Flexible transaction handling
- Improves reliability
- Supports complex workflows
- Enables independent operations
Disadvantages of Improper Propagation Usage
- Deadlocks
- Performance overhead
- Complex debugging
- Unexpected rollbacks
Best Practices for Propagation
- Use REQUIRED by default
- Use REQUIRES_NEW carefully
- Keep transactions short
- Avoid unnecessary nested transactions
- Use SUPPORTS for read-only operations
Common Interview Questions on Propagation
What is transaction propagation?
It defines how transactions behave between nested methods.
Which propagation type is default?
REQUIRED.
What is REQUIRES_NEW?
It always creates a new transaction.
What is the difference between REQUIRED and REQUIRES_NEW?
REQUIRED joins existing transaction, while REQUIRES_NEW creates separate transaction.
When should REQUIRES_NEW be used?
For audit logs, notifications, and independent operations.
Conclusion
Transaction propagation is one of the most important concepts in Spring transaction management.
It helps developers:
- Control transaction boundaries
- Handle nested transactions
- Improve reliability
- Build scalable enterprise applications
Understanding transaction propagation is essential for Spring Boot developers because enterprise systems often contain complex service-to-service interactions.
Proper propagation management improves:
- Data consistency
- Application reliability
- Scalability
- Performance optimization