Back to blog

Why do your retries keep doing the same job twice?

Thắng Đoàn
Thắng Đoàn

Your automation charges a card, the connection drops, so it retries. Ten minutes later the customer has two charges and you have one angry email. The fix is idempotency, and most teams bolt it on after the first duplicate.

Idempotency, in plain words

A request is idempotent when doing it once has the same effect as doing it many times. MDN defines it exactly this way for HTTP: making a single request must have the same server effect as making several identical requests. Flipping a switch to "on" is idempotent. Sending an invoice is not, because each send creates another invoice. MDN notes that all safe HTTP methods are idempotent, plus PUT and DELETE. POST and PATCH are not guaranteed to be.

Why automations specifically need it

Automations retry because networks fail. AWS's Builders Library explains that failures come from servers, networks, load balancers, software, and operator mistakes, and that it is impossible to build systems that never fail. Their answer is timeouts, retries, and backoff with jitter, so retries do not overwhelm a struggling service. But every retry repeats the same request. If that request creates something, the retry creates it again. MDN puts it simply: a client can safely retry an idempotent request, because no harm is done if duplicates arrive.

The idempotency key pattern

Stripe's API shows the standard fix. When creating or updating an object, the client sends an idempotency key alongside the request. Stripe states this lets you safely repeat a request after a connection error without creating a second object or performing the update twice. The key turns "is this a new request or a retry?" into a lookup the server can answer.

Intent is not enforcement

Your automation's safety depends on what the receiving system actually implements, not what the method name implies. Here is the trap. MDN warns the HTTP spec only defines idempotency as intended effect, and nothing prevents a server from ignoring the semantics. In practice, the server must enforce it. So your automation's safety depends on what the receiving system actually implements, not what the method name implies.

What this does not solve

Idempotency prevents duplicate effects from retries, nothing more.

  • It does not decide whether the operation is business-correct in the first place.
  • It does not order concurrent requests that race each other.
  • It does nothing if your client generates a fresh key for every attempt.
  • Retries still need backoff with jitter, per AWS, or you can magnify small failures into an outage.
Which of your automations retry POST calls today, and what happens if two copies of the same request land?
For each external API you call, do you know whether it enforces idempotency or only advertises it?

Pick one retrying automation you own and trace what happens when its request runs exactly twice.

Sources

Stripe: Idempotent requests

AWS Builders Library: Timeouts, retries, and backoff with jitter

MDN: Idempotent

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

By subscribing you agree to receive the newsletter. No spam, and you can unsubscribe anytime.