E-commerce Checkout
Designing a resilient checkout pipeline: cart, pricing, inventory, payments, and orders.
Gateway + Orchestrator + Payments + Inventory + Orders with events
Requirements
- Cart and promo codes; taxes and shipping
- Atomic order placement with payment authorization/capture
- Inventory reservation and decrement
Non-functional Requirements
- High availability: 99.9%+ during peak sales
- Idempotency for checkout retries
- Observability for payment/inventory failures
High-Level Design
- Checkout orchestrator drives the saga across services
- Payment authorization before order confirmation; capture on shipment
- Inventory reservation with timeouts; eventual consistency to stock
Capacity & Sizing
- Peak TPS during sales events; orchestrator horizontal scale
- Reservation TTL sizing vs available inventory
- Ledger/event storage growth from orders and payments
Key Components
- Checkout Orchestrator (saga), Payment adapter(s)
- Inventory reservation and stock service
- Order service and events outbox
Data Model
Orders, items, payments, and inventory reservations
- orders (
order_idPK,user_id,status,total,currency,created_at) - order_items (
order_id,sku,qty,price) - payments (
payment_idPK,order_id,provider,status,auth_id,amount) - inventory_reservations (
reservation_idPK,sku,qty,expires_at,order_id)
APIs
- Add to cart:
POST /api/cart/itemswith body{ sku, qty } - Checkout:
POST /api/checkoutwith body{ cartId, paymentMethod, address } - Order by id:
GET /api/orders/:id
Hot Path
- Validate cart → reserve inventory → authorize payment
- Create order → emit events → finalize reservations
Checkout Flow
- Validate cart, promotions, taxes, and shipping
- Reserve inventory per SKU with expiry
- Authorize payment with idempotency key
- Create order; emit events; release or adjust reservations on failure
Scaling
- Shard orders by
order_idprefix; scale orchestrators horizontally - Use queues for retries and outbox pattern for event delivery
- Rate limit external providers; circuit breakers and fallbacks
Caching & TTL
- Cache product/pricing lookups; invalidate on catalog changes
- Short TTL caches for tax/shipping quotes
Failure Modes & Mitigations
- Payment timeout → retry with idempotency; mark pending
- Inventory race → conditional updates and reservations with TTL
- Partial failures → saga compensation (refund/cancel)
Observability
- Track auth/capture success rates, fraud flags, and stockouts
- Trace across orchestrator, payment, and inventory services