๐——๐—ฒ๐˜€๐—ถ๐—ด๐—ป๐—ถ๐—ป๐—ด ๐—œ๐—ฑ๐—ฒ๐—บ๐—ฝ๐—ผ๐˜๐—ฒ๐—ป๐˜ ๐—”๐—ฃ๐—œ๐˜€

A user gets charged twice. This happens when your API lacks idempotency. Idempotency means the same request always produces the same result.

Use an idempotency key. The client sends a unique key in the header. Your server checks this key. If the server saw this key before, it returns the old response. It does not run the operation again.

Implementation tips:

Choose your methods:

Handle retries on your server:

Test your system:

Document the contract. Tell users which endpoints are idempotent. Explain how to make keys. List the response codes.

Source: https://dev.to/therizwansaleem/designing-idempotent-apis-why-it-matters-and-how-to-do-it-right-gf4