Database transactions keep dependent writes from becoming partial outcomes
A transfer that debits one account without crediting another leaves a business operation incomplete.
PostgreSQL describes transactions as grouping multiple steps into one operation that either completes together or has no effect.
I would identify which database changes must succeed together before implementing their individual update statements.
That decision places the business invariant ahead of the convenience of separate persistence calls.
If integration tests expose mismatches, then optimistic feedback must remain distinct from confirmed database completion.
Tests should interrupt the operation between dependent writes and verify that partial database results never remain.
This database guarantee does not automatically include an external payment service or another independent system.
Define the transaction boundary explicitly, and verify failures inside that boundary before promising atomic outcomes.