ENGINEERING NOTE ·

Idempotency in Payment APIs: Why a Retry Must Never Become a Second Charge

Lessons from building and testing customer-scoped idempotency, SHA-256 payload fingerprinting and PostgreSQL 18 concurrency controls in SecurePay.

The Failure Mode: Network Timeouts Under Uncertainty

When a mobile app, checkout service or ERP integration sends a POST /api/payments request and the connection drops before receiving the HTTP response, the caller faces an ambiguous state: did the payment service commit the charge or did the request fail before reaching the database?

If the client retries without an idempotency contract—or if two concurrent threads send the same retry simultaneously—a naive API creates two distinct payment records and charges the customer twice.

Three Design Rules Implemented in SecurePay

POST /api/payments HTTP/1.1
Authorization: Bearer <signed-jwt>
Idempotency-Key: ord-2026-10-26-001
Content-Type: application/json

{"merchantId":"merchant-456","amount":10.00,"currency":"USD"}
PostgreSQL 18 concurrency test execution and HTTP 409 Problem Details response in SecurePay.
PaymentIdempotencyPostgresTest execution (120 automated tests) and RFC 9457 Problem Details response on payload conflict.

Defense in Depth: Rate Limiting, Ownership & Observability

Around the idempotency core, SecurePay layers controls verified across 120 automated tests: