Distributed

Idempotency Keys

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\n# This pattern is architectural.\n\nclass Service:\n    def execute(self):\n        # Implementation logic\n        pass