Generated with DevPilot
Date: 2026-11-11
Incident Reference: INC-8921
Target Repository: example-org/nexus-commerce
When customers click the "Place Order" button on the web checkout page, intermittent duplicate order records are created in the database (typically 2 identical orders created within 100-300ms of each other), resulting in duplicate payment authorizations.
POST /api/v1/orders/checkout (src/routes/order.routes.ts:84)
└─► OrderController.checkout (src/controllers/order-controller.ts:45)
└─► OrderService.createOrder (src/domain/order/order-service.ts:112)
├─► PaymentGateway.authorizeCharge (src/infra/payments/stripe.ts:35)
└─► OrderRepository.saveOrder (src/infra/db/order-repository.ts:50)
- Route handler receives HTTP request and invokes
OrderController.checkout. - Controller calls
OrderService.createOrderwithcartIdandpaymentMethodId. - Payment is authorized with the payment processor via HTTP API call.
- Database order record is created in PostgreSQL.
- Description: Double-clicking the submission button on unstable mobile connections generates two concurrent HTTP POST requests with identical payload. Because no idempotency key is required or passed, both requests execute the full authorization and creation pipeline independently.
- Evidence For:
src/controllers/order-controller.ts:48extractsreq.body, but does not inspect or validate anIdempotency-KeyHTTP header.src/infra/payments/stripe.ts:38callsstripe.paymentIntents.create()without passing{ idempotencyKey }in the request options.- Timestamps in production incident database show two orders created 140ms apart from the same client IP with the same
cartId.
- Evidence Against: None.
- Status: Confirmed Root Cause.
- Description: Cart status is not marked as
LOCKEDbefore initiating payment authorization, allowing a second concurrent request to read the cart before the first request finishes marking it asORDERED. - Evidence For:
src/domain/cart/cart-service.ts:80updates cart status toORDEREDafter payment authorization completes rather than in an initial optimistic lock.
- Evidence Against: Cart status alone would not explain duplicate payment intents if Stripe idempotency was present.
- Status: Secondary contributing factor.
To confirm the race condition locally without production traffic:
- Run parallel curl requests with the same cart payload:
curl -X POST http://localhost:3000/api/v1/orders/checkout -H "Content-Type: application/json" -d '{"cartId": "cart_123"}' & \ curl -X POST http://localhost:3000/api/v1/orders/checkout -H "Content-Type: application/json" -d '{"cartId": "cart_123"}'
- Observe whether both respond with 201 Created and separate order IDs.
DevPilot will not modify any files until you explicitly authorize this change.
- Require Idempotency Key:
- In
src/routes/order.routes.ts: Addidempotency-keyheader to schema validation. - In
src/controllers/order-controller.ts: Check Redis for active/completed idempotency keys before processing.
- In
- Pass Key to Payment Gateway:
- In
src/infra/payments/stripe.ts: Pass the key to Stripe'sidempotencyKeyparameter.
- In
- Optimistic Cart Locking:
- In
src/domain/cart/cart-service.ts: Transition cart toPROCESSINGatomically usingUPDATE cart SET status='PROCESSING' WHERE id=:id AND status='ACTIVE'.
- In
- Unit Test: Add test in
tests/unit/order-service.test.tsverifying that passing an identical idempotency key returns the cached order response without re-invoking payment gateway. - Concurrency Integration Test: Add test in
tests/integration/checkout.test.tsfiring 5 concurrent requests with the same key and asserting exactly 1 order is created and 4 return the idempotent cached receipt.
- Inspected Files:
src/routes/order.routes.ts,src/controllers/order-controller.ts,src/domain/order/order-service.ts,src/domain/cart/cart-service.ts,src/infra/payments/stripe.ts, andsrc/infra/db/order-repository.ts. - Runtime Limitations: Diagnostic conclusions are based on static code analysis and incident log telemetry. Live Stripe webhook re-delivery and downstream warehouse logistics consumers were not inspected.