codebaobab
Python workspace

All problemsData & Systems

Inventory Reservation Service

Build a stock reservation service for checkout from a one-page spec.

Python60 minutesData & Systems

Challenge brief

Read before you begin

Your mission · Build from a spec

Build the reservation service that holds stock during checkout and never sells a unit twice.

In the October sale Copperpot sold 214 units it did not have and cancelled 163 orders, at about $18 each in refunds, support and coupons. Shoppers who left carts also blocked stock for hours. The Winter Sale starts December 12, and checkout needs real holds before then.

  • Target · All public checks
  • Mode · Build from scratch
Skip to round setup

Your assignment

  1. Read docs/spec.md and choose the data model.
  2. Hold an order whole or reject it, with the stock report.
  3. Add confirm, then the clock and expiry.
  4. Handle the new requirement when it arrives.
  5. Write the model and next steps in NOTES.md.

The problem

Stock checked, never held

Checkout reads the stock count, takes payment, and only then subtracts.

Impact: Two shoppers paying at once can both buy the last skillet.

Abandoned carts block stock

The cart table holds units until a nightly job clears it.

Impact: Items show sold out for hours while nobody is buying them.

Reserve, confirm and expiry are stubs

Every reserve, confirm and tick fails with NotImplementedError.

Impact: Checkout cannot switch to holds before the sale.

Context

Units oversold
214
Orders cancelled
163
Winter Sale
Dec 12

Requirements

  • An order is held whole or not at all.
  • Two lines of one SKU count together.
  • Hold only what is available: on hand minus held.
  • A hold expires exactly at reserve time plus hold.
  • Confirm after expiry sells nothing.
  • Expired orders listed in reservation order.
  • stock changes nothing.
  • Bad input raises ValueError naming the field.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

StorefrontShows what is in stock
CheckoutReserves, confirms, releases
Reservation service(Your work)Holds stock, expires holds
PaymentsTakes the payment
SchedulerTicks every minute
Warehouse systemRestocks and ships
Read the connections
  • Storefront → Checkout: cart
  • Checkout → Reservation service: reserve, confirm
  • Checkout → Payments: charge
  • Scheduler → Reservation service: tick
  • Warehouse system → Reservation service: restock
  • Storefront: Product pages; shows sold out when available stock is 0.
  • Checkout: Reserves when the shopper starts to pay, confirms or releases after.
  • Reservation service: simulate(config, events) in reservations/service.py; the Inventory in reservations/services/inventory.py.
  • Payments: Card processor; a payment takes 20 seconds to 10 minutes.
  • Scheduler: Sends a tick every minute so holds expire on time.
  • Warehouse system: Restocks from deliveries; ships confirmed orders.

Details

Full requirements

Functional

  1. simulate(config, events) runs the events in order on a new inventory and returns one result per event. config is {hold, stock}: the minutes a hold lasts and the units on hand for each SKU. Time starts at minute 0.
  2. A reserve {op: "reserve", order, items} holds every line or none of them, because a shopper who gets half an order still calls support. Two lines for the same SKU count together. The result is {order, state: "held", expires} or {order, state: "rejected", short} with the sorted SKUs that do not have enough. A rejected order is not kept, so checkout may retry it.
  3. Only available units can be held: on hand minus held. This is the rule that stops two shoppers from buying the same unit.
  4. Confirm sells a held order (on hand and held both go down). Release puts it back on sale. On an expired hold both return state expired and change nothing, so a slow payment never sells a unit that went back on sale.
  5. A tick moves time. A hold made at minute t expires when the clock reaches t + hold, and the tick lists the expired orders in the order they were reserved. stock returns one row per SKU, sorted, and changes nothing.
  6. Bad input raises ValueError naming the field: hold, stock, order, items, sku, qty, minutes, op; reuse of an order id or a second confirm raises already, releasing a confirmed order raises confirmed, and an order never held raises unknown.

Non-functional

  • Scale: about 1,900 orders on a normal day and up to 14,000 in the first hour of a sale, over 2,300 SKUs.
  • Correctness first: overselling is never acceptable. A held unit cannot be held or sold by anyone else.
  • Latency: a reserve must answer in under 50 ms at the checkout page, and the storefront reads stock every few seconds.
  • Determinism: replaying the event log must reproduce every result exactly. Time and quantities are whole numbers.
  • Cost of a wrong answer: an oversold unit costs about $18 to cancel and apologize for; a unit held too long is a lost sale while it sits in an abandoned cart.

Out of scope

  • Payment, shipping, taxes and prices. The service counts units only.
  • Backorders and waitlists: a rejected order is simply rejected.
  • Concurrency control and the database. Events arrive one at a time, in order.
  • Several warehouses. A second warehouse opens next year and may arrive as a new requirement.
Data model

Config

FieldTypeNotes
holdinteger >= 1Minutes a hold lasts. Copperpot: 15.
stock{sku: integer >= 0}Units on hand for each SKU at minute 0.

Reserve event

FieldTypeNotes
op"reserve"
ordernon-empty stringCheckout order id, for example "CP-10421".
items{sku, qty}[]At least one line; qty is a whole number of 1 or more.

Stock row

FieldTypeNotes
skustringRows are sorted by SKU.
on_handintegerUnits in the warehouse, including held ones.
heldintegerUnits held for orders being paid.
availableintegeron_hand - held: what the next shopper can hold.
Files you are given · 5
  • config/checkout.yaml Production settings: a 15-minute hold, a tick every minute, and the Winter Sale start time.
    # Checkout reservation settings (production).
    warehouse: reno
    hold_minutes: 15          # payment page timeout plus 5 minutes
    scheduler:
      tick_every_seconds: 60
    sale:
      name: winter-sale-2026
      starts: "2026-12-12T08:00:00-08:00"
      expected_orders_first_hour: 14000
  • samples/checkout-rush.json Four orders in the first quarter hour of a sale, one of them retried. Arguments for Preview.
    [
      {
        "hold": 15,
        "stock": {
          "DUTCH-5": 2,
          "KNIFE-8": 3,
          "SKILLET-10": 4
        }
      },
      [
        {
          "op": "reserve",
          "order": "CP-10421",
          "items": [
            {
              "sku": "SKILLET-10",
              "qty": 2
            },
            {
              "sku": "KNIFE-8",
              "qty": 1
            }
          ]
        },
        {
          "op": "reserve",
          "order": "CP-10422",
          "items": [
            {
              "sku": "DUTCH-5",
              "qty": 2
            }
          ]
        },
        {
          "op": "reserve",
          "order": "CP-10423",
          "items": [
            {
              "sku": "SKILLET-10",
              "qty": 3
            }
          ]
        },
        {
          "op": "tick",
          "minutes": 4
        },
        {
          "op": "confirm",
          "order": "CP-10421"
        },
        {
          "op": "reserve",
          "order": "CP-10424",
          "items": [
            {
              "sku": "DUTCH-5",
              "qty": 1
            },
            {
              "sku": "KNIFE-8",
              "qty": 2
            }
          ]
        },
        {
          "op": "tick",
          "minutes": 11
        },
        {
          "op": "reserve",
          "order": "CP-10424",
          "items": [
            {
              "sku": "DUTCH-5",
              "qty": 1
            },
            {
              "sku": "KNIFE-8",
              "qty": 2
            }
          ]
        },
        {
          "op": "confirm",
          "order": "CP-10422"
        },
        {
          "op": "stock"
        }
      ]
    ]
  • samples/checkout-rush-expected.json What the spec says that rush returns, event by event. CP-10422 expires while its payment is still going.
    [
      {"order": "CP-10421", "state": "held", "expires": 15},
      {"order": "CP-10422", "state": "held", "expires": 15},
      {"order": "CP-10423", "state": "rejected", "short": ["SKILLET-10"]},
      {"time": 4, "expired": []},
      {"order": "CP-10421", "state": "confirmed"},
      {"order": "CP-10424", "state": "rejected", "short": ["DUTCH-5"]},
      {"time": 15, "expired": ["CP-10422"]},
      {"order": "CP-10424", "state": "held", "expires": 30},
      {"order": "CP-10422", "state": "expired"},
      {"time": 15, "stock": [{"sku": "DUTCH-5", "on_hand": 2, "held": 1, "available": 1}, {"sku": "KNIFE-8", "on_hand": 2, "held": 2, "available": 0}, {"sku": "SKILLET-10", "on_hand": 2, "held": 0, "available": 2}]}
    ]
  • logs/checkout-2026-10-17.log Two shoppers buy the last skillet in the same second, and the nightly job frees 1,904 units from abandoned carts.
    2026-10-17T08:00:03-07:00 checkout stock_check sku=SKILLET-10 on_hand=1 order=CP-88102 ok
    2026-10-17T08:00:03-07:00 checkout stock_check sku=SKILLET-10 on_hand=1 order=CP-88107 ok
    2026-10-17T08:00:41-07:00 payments charge order=CP-88107 amount=89.00 status=captured
    2026-10-17T08:00:52-07:00 payments charge order=CP-88102 amount=89.00 status=captured
    2026-10-17T08:00:52-07:00 checkout decrement sku=SKILLET-10 on_hand=-1 order=CP-88102
    2026-10-17T09:14:20-07:00 warehouse pick_failed order=CP-88102 sku=SKILLET-10 reason=no_stock
    2026-10-18T02:00:00-07:00 cart_cleanup released_units=1,904 carts=611
  • metrics/oversells-2026.csv Units oversold and orders cancelled in each sale this year, with the cost.
    event,orders,units_oversold,orders_cancelled,cost_usd
    spring-sale,9840,61,48,864
    summer-sale,11205,97,70,1260
    october-sale,13930,214,163,2934
Tickets · 4
  • TASK-201 Read docs/spec.md and decide the data model Reported by Imani (checkout)

    Expected NOTES.md says what the inventory stores for each SKU and each order, and why that is enough to never oversell and to expire holds on time.

    Actual Inventory has on_hand, held and an orders table, but reserve, confirm and advance are stubs and nothing says what an order record holds.

  • TASK-202 Core: hold an order whole or reject it, with the stock report Reported by Imani (checkout)

    Expected The stock report lists every SKU. CP-10421 and CP-10422 are held until minute 15 and CP-10423 is rejected, short on SKILLET-10.

    Actual The stock report works, but every reserve fails with NotImplementedError: "Implement Inventory.reserve using the request contract".

  • TASK-203 Then confirm, then the clock and expiry Reported by Luis (payments)

    Expected Every result matches the expected file: CP-10422 expires at minute 15 and its late confirm sells nothing.

    Actual The first tick fails with NotImplementedError: "Implement Inventory.advance using the request contract".

  • TASK-204 Write down anything you chose to leave out or would do next Reported by Grace (head of e-commerce)

    Expected A short list of what the service does not handle yet and what you would build next, with a reason for each.

    Actual NOTES.md has no entry.

What you hand in
  • Every public check passing, including the new requirement when it arrives.
  • NOTES.md: the data model in a few lines, the order you built it in, and what you left out or would do next.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
States the data model before asking for code, then builds reserve and the stock report, confirm, and ticks with expiry in that order, with the checks run after each.
Directing the assistant
Hands the assistant one method at a time with the spec rule it must follow, such as all or nothing for reserve and at-or-before for expiry.
Checking the work
Works small event lists by hand first, checks the checkout rush against its expected file, and tries a confirm one minute before and exactly at expiry.
Judging the assistant
Rejects a reserve that holds line by line, a check against on hand instead of available, or an expiry that runs one minute late.
Correct result
All checks pass, including two lines of one SKU, expiry at the exact minute, a retried rejected order, and the follow-up warehouses.
Explaining the work
Explains the life of an order and why nothing is oversold in a few sentences a checkout engineer could follow, and names what was left out.
Trade-offs to discuss
  • Expiring holds on a scheduler tick versus checking expiry lazily whenever an order or SKU is read.
  • A fixed 15-minute hold versus one that grows while the payment is still in progress.
  • Rejecting a whole order versus holding the lines that fit and letting the shopper decide.
  • Keeping rejected order ids so retries are visible versus letting checkout reuse them.
How you are graded
  • Decomposition 25%
  • Prompting the assistant 15%
  • Verification 20%
  • Judgment about AI output 10%
  • Correctness 20%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

Build the service that holds stock while a shopper pays. Checkout reserves an order, then confirms or releases it, and a hold expires after a fixed time. The one rule that matters most: never sell a unit twice. The spec is one page. Start with a working core and grow it. Use the AI assistant however you like, and tell me your data model before you ask it for code.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 8 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • What was your core, and how long did it take to get its first check passing?
  • What is your data model, and what did you decide yourself before asking the assistant?
  • Which edge case did you test that the assistant's first version got wrong?
  • What did you leave out, and what would you build next?