Weekly field note
Run the Same Job Twice Before You Accept an Automation
Published November 24, 2026
Queues, functions and webhooks retry on their own, so the guard has to outlive the retry window: five checks for a workflow that moves money, mail or records

*Image: Dozens of trays of mail with USPS nonprofit bulk mail by Yonghokim, licensed under CC BY-SA 4.0.*
Queues, functions and webhooks retry on their own schedule, and an automation platform can add another retry layer on top. Five checks decide whether the second arrival of the same job repeats the effect: the business key, where the key comes from, how long the guard lasts, where a failed attempt ends, and what happens when the effect succeeds but the record write does not.
The same event arriving at the same endpoint twice is a documented case in Stripe's webhook documentation, which states that delivery attempts continue for up to three days with exponential backoff in live mode and that in some cases two separate Event objects are generated and sent. The page tells integrators to log the event IDs they have processed and skip the ones already logged.
Amazon SQS's at-least-once delivery page sets the same expectation for queues: on rare occasions a copy of a message can come back after a receive or delete, so applications should be designed to be idempotent. Lambda's asynchronous invocation page adds that a function can receive the same event multiple times even when it returns no error, because the event queue is eventually consistent, and tells functions to handle duplicate events gracefully.
A single pass through the happy path, where the event arrives once and every step returns success, leaves that duplicate case untested.
Every layer retries on its own
Four documented retry behaviors apply to a workflow that crosses services, and each one runs on a different clock:
- Amazon SQS standard queues deliver each message at least once. Message retention defaults to four days, with a 60 second minimum and a 14 day maximum, so an unprocessed job can return days later.
- AWS Lambda asynchronous invocation retries a function that returns an error two more times by default, one minute and then two minutes later. Throttled and 5xx events are retried for up to six hours, with the interval growing from one second to a maximum of five minutes.
- Stripe webhooks retry delivery for up to three days in live mode, and three times over the course of a few hours in a sandbox.
- n8n's Retry On Fail retries a failed node once an operator enables it, with Max Tries limited to five and Wait Between Tries limited to 5000 milliseconds.
Each of those layers governs delivery. None of them knows what the workflow's side effect is, so every retry hands the same work to code that has to decide whether it already ran.
Two guards at different depths
Stripe's idempotency documentation describes the guard that sits at the provider. The client generates the key, and for API v1 Stripe saves the status code and body of the first request made with it once endpoint execution begins; a retry with the same key returns that saved response, including 500 errors. Keys can be removed automatically once they are at least 24 hours old, a key reused after pruning produces a new request, and the layer compares incoming parameters against the original and errors when they differ.
The other guard is a row in your own table, keyed to the business identity of the job. PostgreSQL's INSERT documentation defines ON CONFLICT DO NOTHING as the alternative action taken when an arbiter constraint or unique index is violated, so the second insert of the same key does nothing. It defines RETURNING as returning only rows that were actually inserted, updated or selected. An insert that claims invoice 4127 therefore returns a row to the attempt that won and nothing to the attempt that arrived second. The same page describes ON CONFLICT DO SELECT as an idempotent insert or get or create, which suits a workflow that needs the existing record instead of a silent skip.
The test itself
Run the job once, then deliver the same job again with the same identifiers. A Stripe event can be resent from the dashboard for up to 15 days after it was created, or with stripe events resend <event_id> --webhook-endpoint=<endpoint_id> for up to 30 days. A queued message can be sent again with the same body.
Count the effect systems after the second delivery: emails in the inbox, rows in the table, charges in the payment list. A count that moves on the second run is the failure, and the five checks below locate the guard that should have stopped it.
Five checks before you accept the workflow
Run these in order. Each answer is a sentence the person delivering the workflow can write down, and a missing answer is the finding.
- Name the effect and its business key. The effect is the thing that costs money or trust when it happens twice: a charge, an email, a ticket, a ledger row. The key is what identifies the same job on a second arrival, such as
order 4127or an invoice ID. A key has to be a value the second attempt reuses, and a request ID minted per attempt changes each time, so it cannot serve as one. - Ask where the key comes from and whether a retry reuses it. Stripe's key works because the client creates it once and sends the same value on each attempt, so the saved response comes back instead of a second operation. A key derived from the business identity, such as
invoice 4127, matches on every attempt even when the handler recomputes it. A key generated fresh inside the retry handler, such as a new random value per attempt, never matches, and the failure looks identical to having no guard at all. - Compare the guard's lifetime with the longest retry window in the chain. The documented windows differ by orders of magnitude: a Stripe v1 key can be pruned after 24 hours, a message in a standard SQS queue waits four days by default and 14 days at most, a throttled Lambda event retries for six hours, an n8n node gets five tries, and Stripe allows a manual resend up to 15 days after the event in the dashboard and 30 days with the CLI. If the guard expires before the last possible retry, that retry runs unguarded. A table row that keeps history covers the far end of the range.
- Ask where a failed attempt ends and who reads it. SQS moves a message to a dead-letter queue after
maxReceiveCountreceives, and its documentation recommends a retention period longer than the original queue's. Lambda discards an event that expires or fails every attempt unless a dead-letter queue or an on-failure destination is configured. Ask for the alarm alongside the queue, because a destination nobody watches loses failures quietly. - Ask what happens when the effect succeeds and the record write fails. Stripe tells integrators to return a 2xx before any complex logic that could time out, which means the endpoint acknowledges before the work finishes. A crash between the effect and the row leaves the next attempt with no record of what happened, and the order inside the handler picks which failure you get. Record first and perform the effect second: a crash in between leaves a claim for work that never ran, so the retry skips an effect that never happened. Perform the effect first and record second: a crash in between leaves no record, so the retry performs the effect twice. For a charge, send the call with the provider key and let Stripe dedupe it, which makes the repeat harmless. For a receipt email, pick effect first and accept the duplicate, or pick record first and accept the miss.
An invented example
The sheet below is invented to show what the answers look like on a realistically shaped workflow. No such run happened for this article, and the identifiers are placeholders.
workflow invoice.paid -> receipt email, ledger row, Slack note
checked 2026-11-23 invented sheet, no audit performed
1 effect + key receipt email: invoice id ledger row: invoice id Slack note: none
2 key origin created when the job is enqueued, reused on every retry
3 guard lifetime ledger row: keeps history
4 failed attempt dead-letter queue after 5 receives, alarm to #ops
5 effect vs record claim the ledger row, mark done after the mail provider returns its id
verdict receipt email and ledger row are guarded; a crash between claim and
send can miss an email, never send two; the Slack note posts twice
The Slack note has no key, so a retry posts a second message, which is the cheapest defect on the list. Row 5 records first, so the sheet accepts a missed receipt email after a crash in exchange for never sending two. Row 4 answers check 4 with a receive count and an alarm channel, though the sheet names no owner for that channel. The lifetime row carries the arithmetic: as long as the ledger rows are kept, the guard outlasts the four day default retention, the 14 day SQS maximum and the 30 day CLI resend window.
Where the guard stops
Stripe's key dedupes calls to Stripe. An email provider without an equivalent offers no such protection, so a repeated send has to be stopped by your own record or accepted as a second email.
A key that can be pruned after 24 hours stops protecting a replay that arrives later, so the table has to cover the window the provider has forgotten.
Ordering is a separate guarantee. Stripe does not guarantee event order, and it tells integrators not to use created to determine event order or to detect events already processed. Event IDs serve to identify duplicate deliveries. For order, the handler has to work with events in any sequence or fetch current state from the API, for example retrieving the invoice, charge and subscription when invoice.paid arrives first. The page also notes that two Event objects can describe one change, which can mean keying on the object ID in data.object together with the event type.
The guard adds a write on the hot path: an extra insert into a table with a unique index. PostgreSQL notes that inserts into such a table might block when concurrent sessions lock or modify rows matching the unique values being inserted. Measure the cost on the busiest path before adding it, and keep the index narrow.
The five checks cover the effects someone can name. A workflow that also updates a CRM through a second integration has effects outside the sheet.
Ask for the second run in writing: the key, the retry window it survives, the order of effect and record along with the failure that order accepts (a miss or a duplicate), the queue that catches the last failure, and the owner of that queue. With those five answers on paper, the duplicate case has a stated cost and a named owner.
---
Read next: Bounded Automation Is the Credible AI Claim
---
Max Petrusenko writes about AI automation, agent configuration and the evidence behind software claims. He works remotely in software development. Read more on Medium, X and LinkedIn.
If this check saves you a double charge, send it to whoever owns the workflow.