Code Room
Code reviewHardcr-g317
Subject Missing rollbackLevel Senior–Staff~22 minCommon in Databases & SQL · Reliability & on-call interviewsIndustries Software development

Question

Review this Go funds-transfer. It opens a transaction, debits, validates, then credits.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewgo
func transfer(db *sql.DB, from, to string, amt int) error {    tx, _ := db.Begin()    tx.Exec("UPDATE acct SET bal = bal - $1 WHERE id = $2", amt, from)    var bal int    tx.QueryRow("SELECT bal FROM acct WHERE id = $1", from).Scan(&bal)    if bal < 0 {        return errors.New("insufficient funds")    }    tx.Exec("UPDATE acct SET bal = bal + $1 WHERE id = $2", amt, to)    return tx.Commit()}
Run or narrate your approach, then ask the coach.