Roadmap › System Design — High-Level Design (HLD) from Basics to Case Studies › Module: Case Studies
Lessons in this course (14)
12. Case study — e-commerce checkout and inventory
Advanced★ Must knowLesson 12 of 14
Requirements: browse catalog, cart, checkout, payment, inventory must not oversell, order history; flash sales with traffic spikes.
text
CDN (images, SPA) → API gateway → Catalog svc (read replicas + cache + search index)
→ Cart svc (Redis)
→ Order svc (SQL) ─ outbox ─▶ Service Bus ─▶ Payment svc / Inventory svc / Email svcKey decisions:
- Inventory consistency: reserve stock in a transaction with a conditional update (
UPDATE Stock SET Qty = Qty - @n WHERE ProductId = @id AND Qty >= @n); release reservations that aren't paid within N minutes. - Payment idempotency: idempotency key per checkout attempt; payment provider webhooks update order status.
- Saga: order created (pending) → payment → inventory confirm → order confirmed; compensate (refund/release) on failure.
- Flash sales: queue-based admission (virtual waiting room), pre-warmed caches, rate limiting, autoscaling.
- Read scaling: catalog is read-heavy → cache + read replicas + CDN.