Database Transaction
A database transaction is a group of database steps that finish together or are all undone together. Its isolation rules say how it interacts with work happening at the same time.
Another example
A bank transfer takes money from account A, adds it to B, and writes one ledger record in one transaction. If B is frozen, all three changes roll back. An outside email is sent from an outbox after commit, not during the transaction.
Main parts
- 01Transaction boundary
- 02Invariant-preserving statements
- 03Commit or rollback
Use it when
Use the smallest practical transaction when related database changes must appear all at once and keep their rules true.
Do not use it when
Do not keep a transaction open while waiting for user input or a remote call. A local transaction cannot cover another service by itself.
Name used in code
BEGIN + statements + COMMIT/ROLLBACK with explicit isolation Before you ship
Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback.
Outcome: Design or review Database Transaction for this system while keeping data correct, secure, and easy to operate. User context: A bank transfer takes money from account A, adds it to B, and writes one ledger record in one transaction. If B is frozen, all three changes roll back. An outside email is sent from an outbox after commit, not during the transaction. Technical concept or control: Database Transaction. Why it fits: Use the smallest practical transaction when related database changes must appear all at once and keep their rules true. Do not use it when: Do not keep a transaction open while waiting for user input or a remote call. A local transaction cannot cover another service by itself. Engineering requirements: Define inputs, outputs, contracts, and rules that must always hold. Set authorization and input checks. Define failures, timeouts, retries, one-time effects, data moves, and compatibility limits. Operations: Add useful signals and logs that hide sensitive data. Set capacity limits and write an operator guide. Test recovery and rollback. Acceptance criteria: Contract and failure-path tests pass. Data and authorization rules still hold during retries and partial failures. Check performance limits, monitoring, recovery, and rollback. Evidence and limits (evidence boundary): It is official for that source. Other platforms or teams may use the term in another way. Unknowns to confirm: Where the code runs, data stores, traffic shape, consistency needs, and the security boundary. Also confirm the compatibility period, service goals, and rollback limits.
Check this request
Review the current use of Database Transaction. Definition: A database transaction is a group of database steps that finish together or are all undone together. Its isolation rules say how it interacts with work happening at the same time. Release checks: Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback. Before changing code, report the evidence you found, gaps, severity, and the smallest safe fix.