ACID Properties of Database Transactions
Fast recall
Quick revision
Core answer
Whether you understand what each ACID property means in practice and can explain why each matters with concrete examples.
Memorizing the four-letter acronym without understanding scenarios where each property prevents data corruption or loss.
ACID does not invent business rules or make every transaction serial; constraints, isolation, concurrency control, and durability settings define the real guarantee.
Interview-ready guide
Interview answer
ACID names four transaction properties.
Atomicity means all changes commit or none do. Consistency means successful work preserves the rules that the schema and application actually enforce. Isolation controls what concurrent transactions can observe, and the selected isolation level determines its strength.
Durability means an acknowledged commit can be recovered after a restart within the configured storage guarantees. In a bank transfer, debit and credit belong to one atomic transaction. A balance rule must still be encoded, concurrent withdrawals may need a lock or conditional update, and the durability configuration protects the committed result.
In Spring, @Transactional declares the boundary and delegates to a transaction manager; by default, a RuntimeException or Error causes rollback while checked exceptions need an explicit rollback rule.
ACID Properties of Database Transactions
Direct Answer
ACID names four transaction properties. Atomicity gives an all-or-nothing outcome. Consistency means successful work preserves the rules the schema and application actually enforce. Isolation controls what concurrent transactions can observe, with strength depending on the isolation level. Durability means an acknowledged commit survives recovery within the configured storage guarantees.
Code Example
@Service
public class BankTransferService {
private final AccountRepository accountRepo;
@Transactional
public void transferMoney(Long fromId, Long toId, BigDecimal amount) {
// Repository methods use SELECT ... FOR UPDATE in a consistent id order.
var from = accountRepo.findByIdForUpdate(fromId)
.orElseThrow(() -> new AccountNotFoundException(fromId));
var to = accountRepo.findByIdForUpdate(toId)
.orElseThrow(() -> new AccountNotFoundException(toId));
from.debit(amount); // checks the encoded balance rule
to.credit(amount);
} // the transaction manager attempts one commit; either both changes persist or neither does
}
The boundary supplies atomicity for the two database changes. The locking query and debit check supply concurrency control and the business rule; @Transactional does not invent either one.
Common Mistakes & Pitfalls
- Assuming repository calls form one unit automatically: Without an outer transaction, repository methods can complete in separate transactions, so related multi-step work may not be atomic.
- Treating isolation as perfect separation: A named level allows particular behaviors, and database implementations differ. Stronger isolation can block or abort work and may require retries; its cost is workload-specific.
- Treating durability as a backup: Durability covers an acknowledged commit within configured storage guarantees. Replication, backups, and recovery procedures cover other failures such as media loss or accidental deletion.
Check your understanding
Answer these without looking back at the article.
- What is the difference between a commit and a rollback?
- What happens if an exception is thrown inside a @Transactional method?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.