Code Room
Code reviewHardcr-g500
Subject Missing rollbackLevel Senior–Staff~20 minCommon in Databases & SQL · Reliability & on-call interviewsIndustries Software development, Technology

Question

Review this Java method that reserves inventory, then charges the card, and undoes the reservation if the charge fails.

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 reviewjava
public void purchase(Order o) {    inventory.reserve(o.sku(), o.qty());    try {        payment.charge(o.card(), o.total());    } catch (ChargeException e) {        inventory.release(o.sku(), o.qty()); // compensate        throw e;    }}
Run or narrate your approach, then ask the coach.