Layer 3 · Go deeper · 12 min
Go deeper
Size it, build it, then make the calls an interviewer will push you on.
Back of the envelope
Size it up
Tap through each step of the arithmetic.
How much CPU does pricing need at the sale peak?
How many shards does the stock-and-holds database need?
How much storage do carts and live quotes need?
How many units sit held at the peak, depending on when you hold?
Build-up · 5 steps
Build the high-level design
One functional requirement at a time, ending with a design that works for one region at moderate traffic.
Step 1 of 5
Add, change and remove items
Carts sit in a key-value store partitioned by cart ID, each line its own item, so two devices adding different items never collide. Titles, prices and stock are read fresh from the online store’s read models.
6 interview moments
You’re the candidate
The interviewer pushes on the hard parts. Pick an approach and see how it holds up.
Deep dive 1 of 6
Interviewer
“Millions add, remove and forget items, and a shopper whose “Add to cart” fails often doesn’t tap again. Where do you keep the cart?”
Your move. Pick an approach:
Deep dive 2 of 6
Interviewer
“A seller reprices, a coupon expires at midnight, a bank offer needs one bank’s card. How do you charge exactly what you showed?”
Your move. Pick an approach:
Deep dive 3 of 6
Interviewer
“Two shoppers tap “Place order” for the last Phone Z5 at the Mumbai FC in the same millisecond. How do you sell it once?”
Your move. Pick an approach:
Deep dive 4 of 6
Interviewer
“Double taps, 4G timeouts, refreshes, two tabs and your own retries between services. How do you create exactly one order and one charge?”
Your move. Pick an approach:
Deep dive 5 of 6
Interviewer
“About 23M carts a day are abandoned. How do you send a reminder an hour after the last edit?”
Your move. Pick an approach:
Deep dive 6 of 6
Interviewer
“At midnight a festive sale opens and traffic jumps 10× within a minute. How do you keep “Place order” working?”
Your move. Pick an approach:
Build-up · 8 steps
Follow one shopper from tap to order
The cart half is wide, partitioned and always writable. The checkout half is narrow, transactional and driven by deadlines. Kafka carries what happened to everyone who reacts later.
Step 1 of 8
Add to cart
One conditional write to that line’s item in a three-zone store, deduplicated by the tap ID, so a retried tap is not a second phone.