WORKEASIER implementation guide · 6 min read
Prevent duplicate webhook executions in n8n with idempotency
Updated
A customer receiving the same automated reply twice is one of the most visible ways an automation fails. It rarely comes from a bug in your logic. It comes from the event arriving twice — and the workflow having no memory that it already handled it. Idempotency is the fix: processing the same event twice has the same effect as processing it once.
Why the same event arrives twice
Webhook senders retry when they do not receive a timely success response. If your workflow takes longer than the sender's timeout — easy with a model call in the path — the sender assumes failure and sends the event again while the first execution is still running.
Helpdesk tools add another source: triggers that fire on ticket updates can fire again when your own workflow updates the ticket. Manual re-runs and n8n retries after a partial failure can also repeat side effects.
Choose an idempotency key
An idempotency key identifies one unit of work. Use the sender's event or delivery ID when there is one. Otherwise build a key from stable fields — for a support ticket, the ticket ID plus the ID of the comment being answered; for a lead, the normalized email plus the form submission ID. Avoid timestamps of when your workflow received the event, which differ between duplicates.
Record processed keys with a unique constraint
Create a table of processed keys with a unique constraint on the key column. As the first step after normalizing the input, insert the key. If the insert succeeds, this execution owns the event. If it fails on the unique constraint, another execution already has it, and this one stops.
Insert first rather than check first. A “does this key exist?” lookup followed by an insert leaves a gap in which two near-simultaneous executions both see “no” and both continue. The database constraint closes that gap.
Add a send lock around public side effects
Some workflows legitimately process an event more than once — for example, to retry after a failed model call. Protect the irreversible step itself: before posting a public reply or sending a message, take a lock keyed to that specific reply and record when it was sent. A retry then skips delivery that already happened.
The WORKEASIER support module combines both: an idempotency guard before triage and a send lock before public replies, with logs that make it possible to see which guard stopped a duplicate.
Respond to the webhook quickly
Reduce duplicates at the source by acknowledging the webhook as soon as the event is validated and recorded, then doing the slow work. In n8n, the Webhook node can respond immediately or via a Respond to Webhook node placed early in the workflow, so the sender gets its success response before the model call.
Test it with real duplicates
Send the same payload twice in quick succession and confirm that exactly one reply or record exists in the destination system, not just in the n8n execution list. Then simulate a failure after delivery and retry, and confirm the send lock prevents a second message.
Frequently asked questions
- Why does my n8n webhook workflow run twice?
- Usually because the sender retried after not receiving a timely response, or because an update made by the workflow re-triggered it. Respond to the webhook early and record an idempotency key so repeated events stop before any side effect.
- Can the Remove Duplicates node replace an idempotency table?
- Recent n8n versions can remember values across executions with Remove Duplicates, which helps for simple cases. A database table with a unique constraint is more robust when executions run concurrently or several workflows share the same events.