Lesson 6 of 16
42. Design E-commerce Cart and Checkout (Amazon / Flipkart)

42.5 What does the whole system look like?

3 min read+10 XP

Step 4: High-level design (10 minutes)

the shopper talks to a cart service backed by a cart store; checkout is an orchestrator that calls pricing, inventory, the orders database and a payment service in front of the gateway; confirmed orders publish events for warehouses and emails.

Figure: the final design. The cart is fast and forgiving; checkout is careful and exact.

Placing an order, step by step:

  1. Preview: checkout re-reads current prices and offers for every cart item and shows any changes.
  2. The shopper taps Place order; the app sends an idempotency key for this attempt (42.8).
  3. The checkout orchestrator creates the order in state created, then reserves stock with conditional updates (42.7), each with a 10-minute hold.
  4. It asks the payment service to start payment with the gateway (with the order ID as the gateway's idempotency key) and moves the order to payment_pending (42.9).
  5. The gateway reports the result by webhook. On success: confirm the holds, mark the order confirmed, and publish order_confirmed through the outbox to warehouses, email and loyalty (Chapters 22 and 23). On failure: release the holds and cancel.
  6. If nothing arrives in 10 minutes, the order expires and stock is released.

Interviewer pushback:

  • "Cash on delivery?" → No payment step: reserve stock, confirm the order immediately, and collect payment on delivery; returns and refusals release stock later.
  • "The orchestrator crashes mid-checkout." → Its progress is in the orders table (the state machine); a recovery job resumes or compensates orders stuck in intermediate states, and expired holds release themselves.

Memory code: "Re-price, reserve, request payment, confirm or release."


Offer: "The interesting parts are cart storage, reserving inventory, idempotent orders, the payment hand-off, and the saga. Which would you like?"