Description
An idempotency key is a unique token that identifies a request. If a client sends the same request with the same idempotency key multiple times, the server will rely on the key to ensure the request is processed only once.
Where to use
- Payment processing APIs. \n
- Unreliable network conditions. \n
- Preventing duplicate actions on retries.
Real World Example
Stripe API: If a timeout occurs during a charge request, the client retries with the same Idempotency-Key. Stripe checks the key and returns the original successful response instead of charging again.
Code Example
# Code Concept for Idempotency Keys
# This pattern is architectural.
class Service:
def execute(self):
# Implementation logic
pass
