Design a Pizza Ordering System
🍕 What is a pizza ordering system? It is the software at the counter of a pizza shop. A customer builds an order from pizzas of different sizes, each with its own toppings. The system prices every pizza, adds them up, and takes off whatever promotion is running when the customer pays.
Interviewers ask this in a few forms: "design a pizza builder", "compute the bill for a pizza order", or "add BOGO and happy-hour pricing to a pizza shop". They are the same design. The builder part is about how a pizza and its price are modelled, the billing part is how an order adds up, and the promotions are the rule that keeps changing. We cover all three in one system.
Requirements
"Design a system for a pizza shop. Customers pick a size and toppings for each pizza, and the shop runs deals like buy-one-get-one and happy hour."
Short prompts like this hide most of the rules. The questions below are the ones whose answers change the code.
Clarifying Questions
You: What decides the price of a pizza?
Interviewer: A base price per size, small, medium or large, plus a fixed price for each topping. Some toppings cost more than others. Prices are in cents.
You: Can a customer ask for the same topping twice, like double cheese?
Interviewer: Yes, and they pay for it twice. A pizza can have at most five toppings.
You: How exactly does buy-one-get-one work?
Interviewer: It runs on Tuesdays. Pizzas are paired within the same size, and the cheaper pizza of each pair is free. A large never pairs with a small.
You: And happy hour?
Interviewer: Every day from 16:00 to 18:00, the whole order gets 20% off, rounded down to the cent.
You: What if both promotions apply, say on Tuesday at 17:00?
Interviewer: They don't stack. The customer gets whichever one saves more.
You: Can the customer change the order after paying?
Interviewer: No. Once it is paid it is closed. Before that they can add and remove pizzas freely.
You: How do we know the time?
Interviewer: Pass it in with each call, in minutes since Monday midnight.
The "best deal, no stacking" answer is the one to listen for. "Apply every promotion" and "apply the best one" lead to different totals and a different shape of code, so settle it before you write any pricing.
💡 Interview tip: Ask how promotions combine as soon as there are two of them. Stacking, best-of, and "in a fixed order" are all common in real shops, and each one is a single line in the right design but a rewrite in the wrong one.
Final Requirements
- The menu has three sizes (small 800, medium 1000, large 1200) and a fixed list of toppings with prices.
- A customer opens an order and adds pizzas to it. Each pizza has a size and up to five toppings; a topping may repeat and is charged each time. Unknown sizes or toppings are rejected.
- Pizzas can be removed from an open order. A pizza's price is its size price plus its toppings.
- The order's total at a given time is its subtotal minus the best promotion that applies then.
- BOGO Tuesday: within each size, the cheaper pizza of each pair is free.
- Happy hour: 20% off the subtotal every day from 16:00 to 18:00.
- Checkout charges the total and closes the order. A paid order cannot change.
- New promotions will be added, so adding one must not touch the order or billing code.
Out of scope
- Payment, delivery, kitchen tickets and order status after payment.
- Menus that change at runtime (we treat the menu as fixed data).
- Coupons and loyalty points (see /low-level-design/shopping-cart for coupons).