Flosight.

reliability

The Retry That Sent the Text Twice

Every reliable automation retries, and every retry will eventually duplicate an action. Idempotency keys are how you keep the retry and lose the duplicate.

Here is the sequence that produces the complaint.

A workflow fires. It calls an API to send a message. The API receives the request, does the work, and starts writing the response. The connection drops before the response arrives. Your side sees a timeout, concludes the call failed, and retries. The customer gets two texts.

Nothing malfunctioned. Every component did exactly what it was built to do. The failure is in the gap between "the work did not happen" and "I did not hear that the work happened", which from the caller's side look identical and are not.

Why you cannot just stop retrying

The obvious reaction is to remove the retry. Send once, and if it fails, it fails.

That trades a visible problem for an invisible one. Networks drop requests routinely, and a workflow that gives up on the first timeout will silently skip real work, at a rate you will not notice because nothing complains. A missed appointment reminder generates no error, no ticket, and one annoyed customer who assumes you are disorganised.

Retrying is correct. The AWS builders' library piece on timeouts, retries and backoff is the clearest writeup of why, and of the second-order problem: a fleet of clients all retrying on the same schedule turns a brief failure into a sustained one. The answer there is exponential backoff with jitter, meaning each attempt waits longer than the last and each client waits a slightly different amount.

But backoff only changes when the duplicate happens. It does not prevent it.

The method matters, and usually is not enough

HTTP has a notion of this already. RFC 9110 defines a method as idempotent when the intended effect of several identical requests is the same as the effect of one. GET, PUT and DELETE are idempotent by definition. POST is not.

That definition is about the intended effect, and it is a property of the method, not a promise about any particular server. It also does not help with the operation that matters most in automation, which is "create a thing", and which is a POST.

So the protocol gives you the vocabulary and not the solution.

Idempotency keys

The working answer is to make the request itself identifiable, so the server can recognise a repeat.

The caller generates a unique key per logical operation, sends it with the request, and reuses the same key on every retry of that operation. The server stores the key with the result of the first successful execution. A second request bearing a key it has already seen does not execute: it returns the stored result.

Three properties make this work, and all three are easy to get wrong.

The key must be generated once, before the first attempt. If the key is generated inside the retry loop, every attempt carries a different key and the server sees three unrelated requests. This is the most common implementation bug and it produces a system that looks correct, passes tests, and duplicates under exactly the conditions it was built to survive.

The key must be derived from the operation, not the attempt. The natural choice is an identifier you already have: the reminder for appointment 4471, the invoice email for invoice 9912. If the workflow re-runs tomorrow for a genuinely new reason, it should produce a new key.

The stored key must outlive the retry window. Keys held for sixty seconds do not protect against a retry queue that drains after an outage, which is the case that produces the worst duplicates, because by then there are thousands of them.

When the other side does not support it

Plenty of APIs you will integrate with have no idempotency support at all. You still have the problem and you have to solve it on your side.

The workable approach is a local record of intent, written before the call and checked before any retry. Before sending, write "about to send reminder for appointment 4471" with a timestamp. After a confirmed success, mark it sent. On a retry, read the record first.

That leaves one genuinely unresolvable window: the call that succeeded remotely and never reported back. In that window you have to choose which failure to prefer, and the choice should be made per action rather than globally.

For a text message to a customer, prefer missing over duplicating. A customer who did not get a reminder is mildly inconvenienced; a customer who got four at midnight is on the phone to you, and may have a complaint with a statute behind it.

For a payment capture, prefer neither, which means do not build it yourself: use a provider that supports idempotency keys and use them.

For an internal state change, duplication is usually harmless, which is why internal steps are the ones worth retrying aggressively.

What to check in a workflow you already run

Three questions, answerable in ten minutes for most automations.

Does any step that touches a customer retry? If yes, does the retry carry the same key as the original attempt, or a fresh one? If there is no key at all, what in the system would notice if the step ran twice?

If the answer to the last question is "the customer", that step is already producing duplicates occasionally, and nobody has connected the complaints to the cause.

Sources

More on this