Design an Order Management System
📦 What is an order management system? It is the part of an online shop that takes over once the customer clicks "Place order". It checks that everything in the order is in stock and holds those units, takes the payment, and then follows the order as it ships and arrives. If the customer cancels, or never pays, it puts the stock back.
You will hear this prompt as "design Amazon's online shopping", "design the order flow of an e-commerce site" or "design order placement and the order lifecycle". They are the same design. The browsing and the cart are a separate problem (see /low-level-design/shopping-cart); here the cart has already been turned into a list of products and quantities, and our job starts there. The two ideas the interviewer is looking for are stock reservation (never sell the same unit twice) and a clean order lifecycle (every order is in exactly one status, and only some moves are allowed).
Requirements
"Design the order system for an online store. Customers place orders, pay, and we ship them. Make sure we never sell more than we have."
The prompt is short, and most of the design hides in what it leaves out. These are the questions that change the code.
Clarifying Questions
You: What can an order contain?
Interviewer: One or more products, each with a quantity. Each product has a price and a stock count.
You: If one product in the order is out of stock, do we ship the rest?
Interviewer: No. Either the whole order goes through or none of it does. Partial orders confuse customers.
You: When do we take the stock: when the order is placed, when it is paid, or when it ships?
Interviewer: When it is placed. Once we tell a customer "order confirmed", the units must be theirs.
You: What happens to an order that is placed but never paid? Do its units stay held forever?
Interviewer: No. If it is not paid within 30 minutes, cancel it and put the stock back.
You: What statuses does an order go through, and when can it be cancelled?
Interviewer: Placed, paid, shipped, delivered, or cancelled. A customer can cancel before it ships. If they already paid, they get the full amount back. After it ships, no cancelling; that would be a return, which is out of scope for now.
You: If a price changes after an order is placed, does the order change?
Interviewer: No. The customer pays the price they saw when they ordered.
You: How do we know the time? And do we talk to a real payment provider?
Interviewer: Pass the time in with each call, in minutes. For payment, assume the provider already said yes; pay just records it.
The third and fourth answers belong together. Taking stock at placement means an unpaid order blocks units that someone else could buy, so we need the timeout to win them back. Whenever you hold a scarce resource for someone, ask how the hold ends.
💡 Interview tip: "Make sure we never oversell" is the real requirement in this prompt. Say it back to the interviewer in your own words ("units are held when the order is placed, and only released by a cancel or a timeout"), and you have already shown you understand the problem.
Final Requirements
- The shop has products, each with a price and an available stock count.
- A customer places an order with one or more lines (product and quantity). The order is placed only if every line has enough available stock; otherwise nothing changes.
- Placing an order reserves its units at once, so no other order can take them.
- An order moves through
PLACED → PAID → SHIPPED → DELIVERED. It can be cancelled whilePLACEDorPAID, and the refund is the total if it was paid, else 0. Any other move is rejected. - An order not paid within 30 minutes is cancelled automatically, and its units go back into stock.
- The total is fixed when the order is placed: the sum of quantity × price at that moment.
- We can look up an order's status, a product's available stock, and a customer's order history.
Out of scope
- The cart, search and product catalog.
- Real payment processing, partial refunds and returns after delivery (we come back to returns in Extensibility).
- Shipping logistics: carriers, tracking numbers, several warehouses (see /low-level-design/inventory-management).
- Several servers placing orders at the same time (Extensibility again).