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)
Score yourself
3 min read+10 XP
Score yourself
Give yourself 0, 1 or 2 points per row.
| Area | 0 points | 1 point | 2 points |
|---|---|---|---|
| Requirements | Started drawing | Cart and order | Oversell, double charge, lost orders, sale peaks and COD agreed |
| Estimates | None | Numbers, not used later | Numbers that separated relaxed carts from strict orders and hot stock |
| API and data | Skipped | Endpoints only | Idempotency key, expected total, holds, order states, price paid |
| High-level design | One service, one DB | Services without flow | Preview, reserve, pay, webhook, confirm/release walked |
| Deep dive | Hand-waved | One topic | Conditional reservation, idempotency, payment states or saga done properly |
| Trade-offs | None named | Named when asked | Raised unprompted (cart availability vs checkout correctness, hold length, late payments) |
| Communication | Long silences | Mostly clear | Thought out loud, checked in, managed time |
12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.
The bar: fresher vs SDE-2
| Fresher | SDE-2 | |
|---|---|---|
| Cart | Table of cart items | Key-value by user, guest merge, prices as hints, always writable |
| Stock | Check then decrement | Conditional update, holds with expiry, hot-row bucketing |
| Orders | Insert on click | Idempotency key, unique constraint, state machine |
| Payment | Call gateway, wait | Async with webhooks, reconciliation, late payments refunded |
| Cross-service | One transaction | Saga with ordered, idempotent compensations and outbox events |
Common mistakes
- Reading stock, then decrementing it, so concurrent buyers oversell.
- Reserving stock when items go into the cart.
- No idempotency key, so a double tap creates two orders.
- Treating payment as synchronous and having no state for "money arrived after we gave up".
- Sending the confirmation email before the order is confirmed.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz