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.6 How is the cart stored?
3 min read+10 XP
Step 5: Deep dives (10 minutes)
- Key-value store keyed by user ID (or a guest ID in a cookie for signed-out shoppers), sharded and replicated. A cart write should never fail: if one replica is down, accept the write elsewhere (Chapter 16's availability-first choice).
- Merging at login: add the guest cart's items into the user's cart, with sensible caps. In the chapter's code,
{dune: 1}plus a guest cart{dune: 2, atomic-habits: 1}becomes{dune: 3, atomic-habits: 1}, and quantities never exceed the per-item limit. - Prices in the cart are hints. Store the price when added, but re-price at checkout and show the shopper what changed. In the chapter's code, a book that dropped from ₹499 to ₹449 is flagged.
- Stock in the cart is a hint too: "only 3 left" is shown, but nothing is reserved until checkout.
- Abandoned carts feed reminder emails (Chapter 33) and expire after weeks.
Memory code: "Never refuse an item; re-price at the till."