Last Updated: May 22, 2026
An order that decrements stock without recording the order leaves the catalog inconsistent. Transactions are how Go programs make sure that pair of writes is all-or-nothing. This chapter covers db.Begin, the *sql.Tx value it returns, the defer-Rollback idiom that keeps transactions honest, isolation levels via BeginTx, and the common bugs that quietly bypass the whole mechanism.