Setup

The ticket: “Stop overselling. Reserve stock when the customer checks out, then charge their card.” An AI assistant wrote most of this, and the unit tests pass.

Context you need:

  • The shop runs 8 web workers behind a load balancer. Flash sales put 200+ checkouts per second on the same few SKUs.
  • payments.charge calls an external payment provider. It raises PaymentTimeout if the provider doesn’t answer in 10 seconds. A timeout doesn’t mean the charge failed; the provider may still complete it.
  • The provider supports an idempotency_key argument.
--- a/shop/checkout.py
+++ b/shop/checkout.py
@@ -1,4 +1,33 @@
 from shop.models import Inventory, Order
 from shop import payments
+from shop.errors import OutOfStock, PaymentTimeout
+
+
+def reserve_stock(sku: str, qty: int) -> bool:
+    item = Inventory.objects.get(sku=sku)
+    if item.available < qty:
+        return False
+    item.available -= qty
+    item.save()
+    return True
+
+
+def checkout(cart, payment_method):
+    for line in cart.lines:
+        if not reserve_stock(line.sku, line.qty):
+            raise OutOfStock(line.sku)
+
+    for attempt in range(5):
+        try:
+            charge = payments.charge(payment_method, cart.total)
+            break
+        except PaymentTimeout:
+            continue
+
+    return Order.objects.create(cart=cart, charge=charge)

Commit before you see the outcome

Your call

List every problem you would flag before approving this PR. Give each one a severity: high, medium, or low.

Move the slider (or use the arrow keys) to set it. 0% is a pure guess; 100% means you'd bet on it.

After you reveal, your answer and confidence are locked. That's the point.