Code Room
Code reviewMediumcr-g640
Subject Database transactionLevel Mid–Senior~22 minCommon in Databases & SQL · Concurrency interviewsIndustries Software development

Question

Review this Node.js order-placement handler.

```js async function placeOrder(pool, userId, items, total) { const { rows } = await pool.query( 'INSERT INTO orders (user_id, total) VALUES ($1, $2) RETURNING id', [userId, total] ); const orderId = rows[0].id; for (const it of items) { await pool.query( 'INSERT INTO order_items (order_id, sku, qty) VALUES ($1, $2, $3)', [orderId, it.sku, it.qty] ); } await pool.query( 'UPDATE inventory SET stock = stock - $1 WHERE sku = $2', [items[0].qty, items[0].sku] ); return orderId; }

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
Run or narrate your approach, then ask the coach.