KatInterview

Build a Shopping Cart Backend for Meal Ordering

System DesignModel answer
MediumModel answerSystem Designsystem-designcart-serviceconsistency

Last updated

Design a scalable, highly available cart service for a meal-ordering app, covering APIs, storage, price drift handling, concurrent edits across devices, and consistency trade-offs.

Scenario

You are building the backend that manages a customer's cart on a large meal-ordering marketplace. A customer browses a restaurant, collects dishes (with options such as sizes, toppings or special notes), and later checks out. Customers often start on a phone and continue on a laptop, and the service must keep working during the dinner rush.

What the service must do

  • Let a customer add dishes to a cart, including chosen options.
  • Let them change quantities or remove dishes.
  • Return the cart on demand, with computed totals and an indication of whether the restaurant and each dish can currently be ordered.
  • Keep the cart saved so it appears on any device the customer signs in from.

Quality goals

  • Fast reads and writes.
  • Editing keeps working even when some neighbouring internal services are slow or overloaded.
  • Prices shown must follow what the restaurant's menu service currently reports.

What to deliver

  1. A high-level architecture, described or sketched.
  2. An API design covering add, update, remove and get.
  3. A storage schema listing the stored fields.
  4. A plan for stale data, for example a dish whose price changes or which becomes unavailable after being added.
  5. A discussion of strong versus eventual consistency and where each fits.

State your traffic assumptions explicitly and explain how they shape your choices.

Hints

Hint 1

Estimate the scale first (daily carts, mutations per cart, peak multiplier, bytes per cart). The data volume turns out small, so the hard parts are latency, availability and correctness rather than storage size.

Hint 2

Think of the cart as a draft and the order as a binding contract. Which operations can tolerate slightly stale prices, and which must recompute authoritatively?

Hint 3

Separate the concurrency problems: duplicate requests from one device, simultaneous adds from different devices, and conflicting edits to the same line each need a different mechanism.

Hint 4

Decide what happens when the pricing or menu dependency is down. Edits should still succeed, reads should degrade gracefully, and only checkout should refuse to proceed.