← Questions

Cart and pricing engine for a food delivery order

0
UberOO designLast asked Jan 2026

An object-oriented design interview question asked in Uber's coding round, last asked Jan 2026. It tests object-oriented design, design patterns and pricing.

Design the core classes of a cart and pricing engine for a food delivery marketplace. The final checkout price is rarely just the sum of the menu items. It depends on item customizations (extra cheese, no onions, a larger size, each costing $0 or more), surge pricing applied as a multiplier at peak times or in bad weather, promotions (flat coupons such as $5 off, percentage coupons such as 10% off, buy one get one free, tiered delivery fees), and membership benefits (for example free delivery and 5% off eligible items). This is an object-oriented design round: clean class boundaries, the right patterns and a correct, traceable pricing pipeline, not distributed systems.

Requirements

  • Functional: cart operations: add and remove items, change quantities, apply customizations to an item.
  • Functional: several independent pricing rules (surge, membership, coupons, buy one get one, delivery fees) that compose, and a new rule can be added without touching the cart or the existing rules.
  • Functional: an itemized receipt with at least base prices, add-ons, fees, discounts and the final total.
  • Non-functional: exact money arithmetic (no binary floating point); pricing is deterministic, so the price shown at preview equals the price charged; the total is never negative; no discount exceeds the amount it applies to; receipt lines sum exactly to the total.

Main classes and operations

Unless you agree on a different design with the interviewer, name at least: Money, MenuItem, Customization, CartLine, Cart (add_item, remove_item, set_quantity, customize), a PricingRule interface, a PricingEngine (price(cart, context) -> Receipt), Receipt and ReceiptLine.

Clarifying questions

  • Do coupons stack with each other, and with membership discounts?
  • Does surge apply to the item subtotal only, or also to fees?
  • Do percentage discounts apply to food only, or to fees too?
  • Buy one get one: the same item, or buy A get B? Are the free item's add-ons free too?
  • Is free delivery shown as a $0 fee or as a fee plus a waiver line?
  • Round per line or once at the end, and with which rounding mode?

What a strong answer covers

  • The cart stores only selections (lines, customizations, applied coupon); a separate engine derives the receipt, so the cart never holds a stale price.
  • A Money value type in integer cents with a currency, and an explicit rounding policy used only where a rate or multiplier is applied.
  • Each pricing feature as a strategy behind one PricingRule interface, run by the engine as an ordered pipeline where each rule appends lines to a receipt builder.
  • Order expressed as named phases (itemize, surge, fees, discounts, final adjustments) rather than magic priority numbers, with one defined base for every percentage discount, and each policy choice stated for the interviewer to accept or change.
  • The hard sub-rules done properly: surge kept distinct from fees, buy-one-get-one pairing and add-ons decided, flat and percentage coupons unified with a cap so a discount never exceeds its base.
  • Stacking, eligibility and rounding pulled into small policy objects instead of being hard-coded in each rule.
  • A worked example: one concrete cart priced line by line to its total.
  • Tests: one per rule, a golden receipt, and checks that lines always sum to the total.

Follow-ups

  • Add a city tax applied after all discounts and a small-order fee under $10. Show what you add and why nothing else changes.
  • A promotion gives "$5 off, but never more than 50% of the order". Where does that cap live?
  • Marketing wants percentage discounts applied to the pre-surge subtotal. How big is that change?
  • How do you guarantee the preview price equals the charged price if surge or a coupon changes in between?
  • How do you test buy one get one together with a percentage coupon so a later change cannot double-count?

Where it's asked

  • Uber · Coding · Last asked Jan 202660 min · Two rounds; one is often object-oriented design (a parking lot, a meeting scheduler, an expression evaluator) · No AI, except a newer AI-assisted debugging round in some senior loops

What it tests

object-oriented design · design patterns · pricing

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing