Code Room
Code reviewHardcr-g639
Subject Transaction isolationLevel Mid–Senior~25 minCommon in Databases & SQL interviewsIndustries Software development

Question

Review this Go function that deducts from a wallet balance.

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 Withdraw(ctx context.Context, db *sql.DB, userID int64, amount int64) error {    var balance int64    err := db.QueryRowContext(ctx,        "SELECT balance FROM wallets WHERE user_id = $1", userID).Scan(&balance)    if err != nil {        return err    }    if balance < amount {        return ErrInsufficientFunds    }    _, err = db.ExecContext(ctx,        "UPDATE wallets SET balance = $1 WHERE user_id = $2", balance-amount, userID)    return err}
Run or narrate your approach, then ask the coach.