Design an online shop 00:00:00 Make a prediction You will model cart intent, stock reservation and purchase confirmation as distinct facts and trace an all-or-nothing failure. Two carts each show the last keyboard. Does clicking add to cart have to reserve it for both customers? A cart can represent individual intent without guaranteeing stock. If adding is intended to reserve, it must instead create a unique hold with an expiry. Agree on which meaning the product promises. 00:00:31 Honey by rope A shopkeeper sells honey by rope delivery. Looking at the last jar on a shelf does not set it aside. Tying the buyer's tag to it does, until the timer or completed sale removes that claim. Browsing and cart changes are cheap intentions; a reservation excludes competitors. Make the transition visible so the interface never promises more units than the system can allocate. An online shop in a low-level design round is the program from the first look at a product to the parcel at the door: catalog, cart, checkout, payment, order. Everybody has bought something, so the domain needs no explanation. The discussion begins at once with classes and goes quickly to what happens when something fails. 00:01:15 Reserve items before confirming sale A cart shows one remaining keyboard. A second cart can show the same keyboard because adding to a cart need not reserve inventory. At checkout claim the stock under a reservation identifier and expiry. If another buyer won first, return a clear out-of-stock result before promising shipment. Confirm the order against the reservation and payment outcome. Repeating checkout after a lost response must recover the original order for the same request. Reserve the chosen inventory quantities before confirming the order. A later payment failure releases the reservation and leaves a recorded failure result. If the reservation is silently abandoned because a caller closed its browser, other buyers see stock disappear until a cleanup action restores it. 00:02:05 A failed second item A basket contains a mouse and a keyboard. The mouse can be reserved but the keyboard is unavailable. For an all-or-nothing order, release the first reservation or roll back the transaction. Otherwise a failed order quietly hides saleable inventory from other customers. Claim the mug and then discover that the book is unavailable. Under an all-or-nothing basket policy, release the mug and report that the order was not confirmed. A partial-order policy would produce a different result and must tell the customer which item actually succeeded. Charging before protecting stock can create a paid order that cannot be fulfilled. Reversing blindly can also leave indefinite holds when payment fails. State the sequence and recovery plan. For partial fulfilment, explicitly represent unavailable lines rather than pretending the whole order succeeded. Adobe Commerce inventory. Keeps a salable quantity apart from the quantity at each source. Reservations lower the first at checkout, and when an order ships the reservation clears and the source goes down. The split of this design between held and on hand. Shopify inventory states. An inventory level has several quantities such as available, on hand, incoming and committed. An order moves pieces from available to committed, and fulfilment lowers committed. 00:03:30 Try an interview follow-up Why should stock not be a field of Product? They change at different speeds and for different people. A product is read all the time and edited by staff. Stock changes with every checkout, needs a lock and a history. If both have a number, they will differ. Product stays a record, Inventory is the only owner. A customer sees a price in a basket and the catalogue changes a minute later. Ask when the price becomes binding. Price the checkout under that rule, record the amount and currency on each order line, and issue the receipt from the recorded order. A later catalogue edit should not rewrite yesterday's purchase. 00:04:11 What to take with you Catalog, cart, inventory and order are four objects, because they change at four speeds. The cart holds no prices and no stock. The order copies what was agreed. Place: price again and compare, store PENDING under the key, hold all lines, authorise, sell, and look at the answer. Every step has the order's key and an undo, and a job finishes or voids what was interrupted.