← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 028 · Databases and storage

Design an E-commerce Checkout

Medium 50 min

Design the checkout for an online shop selling 200,000 products. A shopper reviews their cart, enters an address and pays by card through an external payment provider. On normal days the shop takes 30 orders per second; during the Black Friday sale it peaks at 600 checkout requests per second, and popular items sell out in minutes. Shoppers double-click, mobile networks drop and retry, and the payment provider is sometimes slow: none of this may produce two charges, two orders, or an order for stock that does not exist.

Functional requirements

  • Persist carts and show up-to-date prices and stock at checkout
  • Reserve stock while the shopper pays, and release it if payment fails or times out
  • Charge the card through an external payment provider
  • Create exactly one order per checkout attempt and send a confirmation email
  • Let shoppers see the status of their order

Non-functional requirements

  • Never charge a shopper twice or create duplicate orders for one checkout
  • Never sell more units than are in stock
  • Checkout responds within 1.5 seconds at p95, including payment authorisation

Constraints and scale

  • Peak of 600 checkout requests per second on Black Friday
  • Payment provider allows 1,000 calls per second and takes about 250 ms per call
  • Stock reservations expire after 10 minutes

You will practise

  • Use idempotency keys end to end, from the browser to the payment provider
  • Keep order and stock changes consistent with database transactions
  • Move non-essential work (emails, fulfilment) off the checkout path with a queue
Show 3 hints
  1. The browser retries a request whose response was lost. How does the server recognise it has already done the work?
  2. Which steps must succeed before you answer the shopper, and which can happen a second later?
  3. What happens to reserved stock if the shopper closes the tab?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • The payment response never arrivesThe provider charges the card, but the connection drops before your service receives the reply. The shopper's app shows a spinner and then retries.
  • A doorbuster sells out in 40 seconds500 units of a discounted console go on sale and 20,000 shoppers press 'Pay' within the first minute.

Run them from the workspace once your design is in place.