Q58: How would you design an e-commerce checkout system?
Model checkout as explicit states such as created, inventory-reserved, payment-authorized, confirmed, and cancelled. Reserve inventory with concurrency control, call payment providers with idempotency keys, and coordinate steps with a saga. Persist state transitions and publish events through an outbox. Handle payment timeouts with reconciliation because a timeout does not prove a payment failed. Use compensations such as releasing inventory or refunding an authorized charge, and make every transition observable and retry-safe.
Key Takeaways
- Represent checkout as a durable state machine.
- Payment timeouts require reconciliation; retries must be idempotent.