Transactions & ACID
A transaction is a group of operations that either all succeed or all fail together. ACID is the set of guarantees that make this work: Atomicity (all-or-nothing), Consistency (data stays valid), Isolation (concurrent transactions don't interfere), and Durability (committed data survives crashes).
Isolation levels control how visible uncommitted changes are to other transactions. Read Committed (the Postgres default) prevents dirty reads but allows non-repeatable reads. Serializable provides the strongest guarantee but reduces concurrency. Most applications work well at Read Committed — only use Serializable for financial operations where phantom reads would cause real money problems.
Exercise
Wrap a two-step balance transfer (debit + credit) in BEGIN/COMMIT with ROLLBACK on error. Force a failure after the debit and confirm the debit did not stick. Note which isolation level your engine defaults to.