In plain words
An operation is idempotent when doing it twice has the same effect as doing it once, which lets clients retry after a timeout without creating a second charge, invoice or email.
Where you see it
A customer clicks Pay on a Harbor invoice, their train enters a tunnel, and the app retries. With an Idempotency-Key header, the server recognises the repeated key and returns the first result instead of charging again. Stripe's API accepts the same header on POST requests for exactly this reason.
What goes wrong
- Checking for the key without a unique constraint
Two retries arrive together, both find no earlier payment, and both charge. Store keys in a column with a unique index, and record the key before doing the work, so the second insert fails.
- A new key on every retry
If the client makes a fresh key for each attempt, the server sees separate requests. Create the key once per user action, such as clicking Pay, and reuse it for every retry of that action.
- Assuming every request is safe to retry
GET, PUT and DELETE are meant to be idempotent; POST is not. Retry logic that resends POSTs without a key turns a slow network into duplicate charges.
What to tell your agent
Quick check
Sign in to earn +10 XP for itHarbor's mobile app retries a payment request after a timeout, and the customer is charged twice. Which fix addresses the cause?