idempotency-demo · sequence diagram

Scenario E · Provider failure

The payment provider throws. The reservation is released so the key does not stay stuck in PROCESSING, and a retry with the same key can charge normally.

own transaction own transaction Clientcurl / test PaymentControllerPOST /payments PaymentFacadecreatePayment() IdempotencyReserverREQUIRES_NEW H2idempotency_record PaymentServicesimulated provider POST /payments · Idempotency-Key: pago-003 createPayment(key, request) findByKey(pago-003) Optional.empty() reserve(key, hash) INSERT status=PROCESSING COMMIT process(request) RuntimeException (provider down) catch: release the key release(key) DELETE pago-003 COMMIT no row: the key is free exception rethrown 500 Internal Server Error The client retries with the same key POST /payments · pago-003 (retry) createPayment(key, request) findByKey(pago-003) Optional.empty() reserve → INSERT PROCESSING process(request) PaymentResponse (APPROVED) complete → COMPLETED 201 Created 201 Created · paymentId Result: no key stuck in PROCESSING; the retry charges exactly once
Solid arrows: calls. Dashed: replies. Red: errors. Amber: conflicts. Dashed blue boxes: database transactions (each IdempotencyReserver method opens its own); amber boxes: alternative branches.

What to look for