42. Design E-commerce Cart and Checkout (Amazon / Flipkart)
1
The interview prompt2
42.1 What do you ask first?3
42.2 How big is this, really?4
42.3 What are the doors?5
42.4 What do we store?6
42.5 What does the whole system look like?7
42.6 How is the cart stored?8
42.7 How do you reserve inventory?9
42.8 How do you make order creation idempotent?10
42.9 How does the payment hand-off work?11
42.10 How does the checkout saga work?12
42.11 What would you say in the last five minutes?13
Score yourself14
Variations to practise15
Sources16
Code lab42. Design E-commerce Cart and Checkout (Amazon / Flipkart)
42.2 How big is this, really?
3 min read+10 XP
Step 2: Estimates (5 minutes)
Assume about 2 KB per cart, at least 3 writes per order (order, items, reservation), and a 10-minute reservation hold.
| What | Working | Result |
|---|---|---|
| Cart storage | 50 million × 2 KB | ≈ 100 GB: fits a sharded key-value store |
| Peak order writes | 5,000 orders/s × 3 | ≥ 15,000 writes a second at sale opening |
| Hot items | a sale phone with 100,000 units, bought at thousands a second | one stock row under huge contention (Chapter 43) |
| Payment calls | 5,000 a second to external gateways | gateways' own limits matter (Chapter 25) |
What the numbers say, out loud:
- "Carts are big in count but simple: a key-value store sharded by user."
- "Orders need transactions: shard the orders database by order or user ID, with replicas."
- "Stock is the hot spot: one popular product means many writes to one row. Conditional updates, splitting stock across warehouses or buckets, and a queue at the front for flash sales (Chapter 43)."
Interviewer pushback:
- "Why not keep the cart in the browser only?" → Guest carts can start there, but signed-in users expect the cart on every device, and abandoned-cart reminders need it server-side. Merge at login (42.6).
Memory code: "Carts are many and simple; orders are fewer and strict; stock is the hot row."