CodePark/ questions / Idempotency keys, webhooks & errors
START PRACTICINGPRACTICE
Backend question · HTTP & API design › Idempotency keys, webhooks & errors

A client reuses an Idempotency-Key from a successful POST /payments of 50 EUR, but this time the body says 80 EUR. What should the server do?

Reject the request with an error, because the key is bound to the original request

Reject the request with an error. The key identifies one specific operation. The server stores a fingerprint of the original request, which is a hash of its body. A reused key with a different body doesn't match, so the server rejects it as a client error.

"Return the stored 50 EUR response" is tempting, but it would hide a client bug. The client would think its 80 EUR request succeeded.