Design a Resilient E-Commerce Checkout
Coordinate authenticated checkout, inventory allocation, payment, and refunds across partial failures.
Problem statement
Design a distributed checkout service for an e-commerce platform, focusing on authentication, inventory failures, payment handling, reliable processing, and refunds when inventory allocation fails.
For this exercise, assume a checkout request contains an immutable cart snapshot, currency, shipping choice, and idempotency key. Inventory reservations expire, payment providers can return uncertain outcomes, and the service must never silently charge twice or promise stock it did not reserve.
Cover workflow state, APIs, authentication, inventory and payment boundaries, compensations, retries, observability, and recovery. Catalog browsing, warehouse fulfillment, and card-network implementation are outside scope.
Checkout code review
For this exercise, review this deliberately flawed sketch after presenting your design:
if stock[sku] >= quantity: stock[sku] -= quantity charge(paymentToken) createOrder(cart)
Assume these calls do not, by themselves, share an atomic commit or a durable request identity. Explain the concurrency, retry, and uncertain-outcome risks, and describe changes using the authority and recovery boundaries of your design. This sketch is a practice follow-up; no original interview code is available.
What to build
- Authenticate the shopper and idempotently create one checkout from an immutable priced cart.
- Coordinate expiring inventory reservation and payment authorization with explicit pending and failure outcomes.
- Commit one order only after required inventory and payment conditions are satisfied.
- Release inventory and void or refund payment after partial failure with durable evidence and safe retries.
At scale
- For this exercise, assume 20,000 checkout attempts per second at peak and individual SKUs that can receive 5,000 competing requests per second.
- For this exercise, return a terminal or explicit pending response within three seconds at p95; uncertain provider outcomes may resolve asynchronously.
- For this exercise, retain financial workflow and idempotency evidence for seven years while inventory reservations normally expire after ten minutes.
- For this exercise, a zone failure must not lose an accepted checkout transition or authorize a second physical charge for the same logical attempt.