Idempotency
Ensuring idempotency
Overview
An idempotent operation or function is one where it can be executed multiple times without changing the result beyond the initial execution.
This characteristic is essential for building robust, fault-tolerant systems that can handle network failures, timeouts, and retry scenarios gracefully.
Implementation in Payment Systems
For APIs involving money movement, idempotency is a critical safety mechanism that prevents duplicate transactions when clients need to retry the API request.
In Pave, idempotency ensures that a client who calls a supported endpoint with the same idempotency key is able to call the API multiple times without generating multiple payments or accounts.
Supported Endpoints
- Transfers:
rtgs,account,internal,external - Transfer returns
- Segregated wallet transfers
- FX transactions
- Crypto orders
- Nominal account and nominal sub-account creation
The Idempotency-Key header is required on all of these endpoints.
Idempotency Behaviour
Transaction Creation
Clients should pass in an idempotency key in their request header. A random UUID per request is a good choice.
When a client creates a request with an idempotency key, the system will exhibit the following behaviour:
- First Request: Processes the request. Success returns the created ID; failure returns the error
- Second Request: Returns the same response as the first request when using an identical idempotency key and body. Nothing new is created
- Immutability: Sending the same idempotency key with different fields returns
400 Bad Request. A key identifies one exact request, so send a changed request under a new key - First Request Failed: Returns the same error as the first request, including
5xxerrors. Fix the request and send it under a new key - First Request Still Processing: Returns
409 Conflict. Wait briefly and retry with the same key
Key Lifecycle Management
- Expiration: Idempotency keys have a 24-hour time-to-live (TTL). After expiration, subsequent requests with the same key will be processed as new operations
- Scope: Keys are isolated per client and per endpoint
Error Handling
An error on a retry is the error the first request produced. Treat it as you would on a first attempt: a 400 means the request was invalid, a 403 means the account cannot be used, and so on.
A 5xx on a retry means the first request also failed with a server error, and the same key keeps returning it until the key expires. Before sending the request under a new key, check the transactions list, or the nominal accounts and nominal sub-accounts lists for account creation, to confirm nothing was created.
Only these responses relate to the key itself:
409 Conflict, messagerequest with this Idempotency-Key is still being processed, retry shortly: wait briefly and retry with the same key400 Bad Request, messageIdempotency-Key was already used with a different request payload: send the changed request under a new key503 Service Unavailable, messageidempotency store unavailable, retry shortly: the request was not processed. Retry with the same key
If a 409 persists for more than a few minutes, contact your Pave integration partner with the key and endpoint before creating a new transaction.