Design an e-commerce checkout system
HardConceptMedia & Commerce
Answer
Requirements: convert a cart into an order, reserve stock without overselling, charge the customer exactly once, and stay responsive during flash sales.
- Services: cart, inventory, order, payment and notification services; each order follows a state machine from created through paid to shipped or cancelled.
- Inventory: reserve stock with an atomic conditional update that decrements only if enough quantity remains, and release reservations that are not paid within a time limit.
- Payment: call the payment gateway with an idempotency key so that retries never double-charge, and confirm the outcome through gateway webhooks.
- Trade-off: instead of one distributed transaction, use a saga, a sequence of local steps with compensating actions such as releasing stock when payment fails; this gives eventual rather than immediate consistency.
More in Media & Commerce
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Design a video streaming service like YouTube | Concept | Hard | Read the answer to Design a video streaming service like YouTube | |||
| 2 | Design a ride-hailing service like Uber | Concept | Hard | Read the answer to Design a ride-hailing service like Uber | |||
| 3 | Design an e-commerce checkout system | Concept | Hard | Read the answer to Design an e-commerce checkout system | |||
| 4 | Design a distributed file storage service like Dropbox or Google Drive | Concept | Hard | Read the answer to Design a distributed file storage service like Dropbox or Google Drive |