Design E-Commerce Order Checkout & Inventory Saga
A resilient order checkout engine that coordinates inventory reservations, payment gateways, and fulfillment across microservices. It guarantees zero double-charging and eliminates overselling during high-demand flash sales using the distributed Saga pattern.
Live Architecture Studio
Edit components, modify labels, add databases, or redraw connections directly on this canvas:
1. Problem & Challenge
During flash sales, thousands of shoppers compete for the same stock. Multi-database 2-Phase Commit (2PC) is too slow and fragile. If a payment fails after stock is locked, inventory must be released automatically without manual intervention.
2. Core Building Blocks & Responsibilities
👉 Swipe table horizontally to view roles and responsibilities| Component | Role | Plain-English Explanation |
|---|---|---|
| Checkout Web Client | Order Portal & Timer | Submits checkout cart with UUID Idempotency-Key and displays 15-minute reservation timer. |
| Saga State Machine | Distributed Coordinator | Tracks transaction progress and triggers compensating rollback actions if payment or inventory fails. |
| Inventory Service | High-Concurrency Stock Locker | Executes MySQL 8 SKIP LOCKED or Redis TTL locks to temporarily hold units for 15 minutes. |
| Stripe Payment Gateway | Financial Capture Gateway | Authorizes credit card, performs 3D Secure verification, and captures customer funds. |
| Webhook Processor | Asynchronous State Finalizer | Ingests charge webhooks, validates signature headers, and transitions orders to PAID. |
| Fulfillment & Warehouse Worker | Dispatch & Notification Worker | Emits warehouse picking tickets and sends customer tracking receipts. |
3. Step-by-Step Request Flow
Customer Submits Checkout
Customer clicks Place Order with an Idempotency-Key, starting the 15-minute inventory reservation window.
Saga Workflow Instantiation
Saga orchestrator creates an order record in PENDING state and coordinates distributed microservice calls.
Inventory Soft Reservation
Inventory service locks units using row-level SKIP LOCKED; releases automatically if checkout expires.
Payment Gateway Authorization
Orchestrator submits payment request to Stripe with the idempotency key, preventing duplicate charges on retry.
Webhook Confirms Payment
Stripe webhook triggers order state transition to PAID, converting the soft reservation into a permanent purchase.
Warehouse Fulfillment Dispatch
Warehouse worker prints picking ticket, packs goods, and sends customer shipping tracking notifications.
4. Architectural Trade-offs
Orchestrated Saga vs Choreographed Events
Chosen: Orchestrated Saga (Step Functions)
Rationale: Centralized state machine makes complex rollback logic, compensating refunds, and timeouts straightforward to audit.
Immediate Inventory Deduction vs Soft Hold
Chosen: 15-Minute Soft Hold with Redis/MySQL
Rationale: Prevents abandoned carts from permanently depleting stock while preventing concurrent overselling.
Interview Tip
Always emphasize compensating transactions: If step 4 (payment) fails, the saga orchestrator immediately triggers ReleaseInventoryReservation to return items back to active catalog stock.
Explore Related System Blueprints
TinyURL Shortener
A URL shortener converts a long link (like a 100-character article URL) into a compact 7-character key (like tinyurl.com/xyz123) and redirects visitors in under 15 milliseconds.
API Rate Limiter
A rate limiter acts as a digital bouncer at the door of your API, ensuring each client stays within their allowed request limits (e.g. 100 requests per minute) and blocking abusive traffic.
Video Streaming CDN
Streaming high-definition video to millions of smart TVs and mobile phones requires breaking large 10GB video files into tiny 5-second chunks, encoding each into 20 different resolutions, and caching them right inside local ISP networks.
Uber Dispatch Engine
A real-time geospatial dispatch system matches riders with the most optimal nearby drivers using 64-bit H3 hexagonal indexing and 2-second batch optimization, minimizing city-wide pickup ETA and driver idle time.
Stripe Payments Ledger
A resilient financial payments architecture guarantees strict consistency (CP system) using cryptographic idempotency reservation, double-entry balanced postings, and sharded balance locks.
Figma Multiplayer Engine
A real-time multiplayer document engine uses stateful sticky session routing and server-authoritative operational ordering to sync 2D scene graphs across worldwide collaborators without locking.