Lesson 9 of 16
42. Design E-commerce Cart and Checkout (Amazon / Flipkart)

42.8 How do you make order creation idempotent?

3 min read+10 XP

Shoppers double-tap "Place order", networks drop responses, and apps retry (Chapter 24):

  • The app creates an idempotency key per checkout attempt and sends it with POST /v1/orders.
  • The orders table has a unique constraint on it; a repeat returns the existing order instead of creating another. In the chapter's code, the second tap returns the same order and the table still has one order.
  • The payment service passes the order ID to the gateway as the gateway's idempotency key, so a retried charge can't charge twice (Chapter 24).
  • Warehouse and email consumers de-duplicate by event ID (Chapters 22 and 23).

Memory code: "One key per attempt, one order per key, one charge per order."