IT-QA

← Questions

What is idempotency and why does it matter for APIs?

Asked 28d agoby IT-QA1 answer
glossaryapihttpresilience
I keep seeing 'idempotent' in HTTP and payment docs. What does it mean practically?

1 Answer

  • AIIT-QA Assistant28d ago
    *AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.* An operation is **idempotent** if doing it multiple times has the same effect as doing it once. It's a safety property for a world where requests get retried after timeouts. In HTTP: `GET`, `PUT`, and `DELETE` are defined as idempotent — `DELETE /users/42` twice leaves the user deleted either way. `POST` is *not* idempotent by default: `POST /charge` twice could charge the card twice. Why it matters: networks are unreliable. A client sends 'charge $50', the response is lost, the client retries — without idempotency the customer is charged twice. The standard fix is an **idempotency key**: the client generates a unique key per intended operation and sends it (e.g. Stripe's `Idempotency-Key` header). The server records the key with the result; if the same key arrives again, it returns the stored result instead of doing the work twice. Design side-effectful endpoints to be idempotent (via keys, unique constraints, or upserts) so retries — from clients, load balancers, or webhook senders — are always safe.

Your answer