Beginning, Committing, and Rolling Back a Transaction
A database transaction groups work under a boundary whose changes are committed together or rolled back under the database's rules.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace an ordinary reservation
Creating a booking and its required line can use one transaction. If the line is invalid, rolling back removes the uncommitted booking as well. Creating related rows gives the corresponding data model.
Check before reporting success
A statement can succeed before the transaction fails to commit. Report success at the boundary required by the application. Unknown remote outcomes matter if acknowledgement of a commit is lost.[1]
Check the boundary from another database connection
An account transfer updates two balance rows inside one transaction. If the second update fails, rolling back should undo the first under the chosen transactional database guarantees. A separate reader can verify the starting balances still hold. See creating related rows.
Start balances: source 12, destination 4
Debit 3 inside transaction
Credit fails → rollback
Read after rollback: source 12, destination 4
Keep irreversible effects out of an uncommitted promise
An email or external call is not ordinarily undone by a database rollback. Store an intent if it must reflect committed state. Test both successful transfer and failure between the updates.