Design an inventory management system 00:00:00 Make a prediction You will distinguish on-hand from available stock and verify the quantities after reserve, ship or cancel. Five mugs are physically on the shelf. A customer reserves two, but nothing ships. What are on-hand and available now? On-hand remains five and available falls to three. A hold represents a promise, not physical removal. After shipment, both the physical stock and the outstanding hold must be adjusted exactly once. 00:00:31 A day in the jam cellar A jam seller ties tags to jars for customers. The tagged jars still stand on the shelf, but the next buyer cannot buy them. When the timer expires, removing the tags restores availability without bringing any new jar into the cellar. Track stock, reservations and fulfilment separately. Movement of a jar and movement of a promise update different facts. An inventory in a low-level design round is the part of a shop that knows how many pieces of each product are in each place, and who they are promised to. It accepts deliveries, reserves pieces for orders, and records what leaves. Promising a piece twice is the mistake everybody understands. A customer has paid and the shelf is empty. The design must make it impossible and not unlikely. 00:01:17 Keep on-hand and available distinct Five mugs are physically in stock. Reserving two leaves five on hand but only three available for another buyer. Give the reservation its own identifier and quantity. Repeating the same confirmed reservation request should not reduce availability twice. When the two mugs ship, reduce on-hand stock and consume the hold. If the purchase is cancelled instead, release the hold and make those two available again. Ten physical items minus four held leaves six that can be promised. Reject seven without changing either count. Release two held items and try the same request again. Now eight are available and a successful hold leaves one available; physical stock has still not left the shelf. 00:02:01 An order spans two products An order requests two mugs and a plate. The mugs are available but the plate is sold out. If partial orders are disallowed, check and reserve all requested lines atomically or roll back partial reservations. Check every quantity after failure, not just the response message. Reserve the mugs, then fail to reserve the second product. For an all-or-nothing order, release the first hold exactly once. Replaying that release must not invent additional available mugs. That test exposes the difference between releasing a named hold and blindly adding a quantity. Retried reservation requests can subtract the same quantity twice unless the logical request has a stable identity. Test quantity and reservation records after replay. If partial fulfilment is allowed, record the accepted quantity per line; do not hide a partial result behind a generic success. Commerce systems distinguish physical quantities from quantities available to promise. Shopify models several inventory states. Adobe Commerce uses reservations until later order events account for the held quantity. In both cases, moving a unit into a held state changes what can be sold before anything physically leaves the warehouse. 00:03:21 Try an interview follow-up Why is a reservation not just a flag on the order? It has its own life and its own data: which pieces from which places, until when, and how it ended. The order has prices, an address and a payment. If one class had both, the inventory would depend on the shop. A warehouse attempts to fulfil a reservation while the expiry worker is releasing it. Can both operations succeed? They compete to transition the same named hold out of its active state. Establish the authoritative time and make the winning transition conditional. Otherwise one worker could ship the unit while another advertises it as available to a new customer. 00:04:06 What to take with you Count a product in a place. Store on hand and held, work out available, and let one small class guard the rule between them. A promise is an object with picks and an end. Reserve plans everything first and holds everything after, under one lock. Ship, release and expiry close it exactly once.