idempotency-demo · sequence diagram

Scenario B · Retry with the same key

The client sends the same request again (for example after a timeout). The stored response is replayed and nothing is charged. Answer: 200 OK.

handleExisting() Clientcurl / test PaymentControllerPOST /payments PaymentFacadecreatePayment() IdempotencyReserverREQUIRES_NEW H2idempotency_record PaymentServicesimulated provider pago-001 is already COMPLETED (scenario A) POST /payments · same key, same body createPayment(key, request) requestHash = SHA-256(body) findByKey(pago-001) record: COMPLETED, same hash stored hash = new hash ✓ status = COMPLETED fromJson(response_body) not called 200 OK 200 OK · same paymentId Result: no new charge; the client gets the original paymentId
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