The message usually arrives on a Sunday: the invoice workflow sent the same invoice twice. The first question is whether n8n is broken. It usually is not. The workflow did exactly what it was told: it received the same event twice and ran twice.
That distinction matters. If you start by adding a delay or a filter on the trigger, you are treating a symptom. The duplicate already exists before the workflow does anything.
Short answer: find the event that entered twice, use the source's own event id as a dedupe key, store that key with a unique constraint, and stop before the side effect if it has been seen. Do not use the n8n execution id. A retry gets a new one.
First, prove the trigger fired twice
Open the execution list and compare the input of both runs. If the input is identical, the event arrived twice. If the inputs are different, the workflow is probably splitting work and one branch is feeding back into the start.
Then check the sender's delivery log. Most webhook providers show every attempt, including the ones they retried. A form tool, a payment provider or an email service will usually tell you whether it sent the same event again after a timeout.
The causes I see most often:
- The sender retried. Webhooks expect a quick 2xx response. If the workflow does forty seconds of work before answering, the sender may time out and send it again. Returning a fast response and doing the work afterwards removes this whole category.
- Two triggers are listening to the same event. A new row trigger and an updated row trigger can both fire for one change. So can an old workflow and its replacement, or a staging copy that was never switched off.
- A loop feeds itself. The workflow updates a record, and the same trigger watches updates on that record. It runs again with the new version of the same event.
- Retry on fail is doing what it says. A retry after a partial success can repeat a step that already happened. Retries are useful, but only on steps that are safe to repeat.
- A manual test ran next to the live trigger. This one is easy to miss when you are debugging at the same time as the schedule.
Exactly once is a story. Idempotent is the goal.
Across two systems, you cannot promise exactly once. The sender can time out after the work succeeded. The network can drop the response. n8n can finish and fail to report that it finished.
What you can do is make the work safe to run twice. Idempotent means the second run has the same effect as the first: one invoice, one contact, one message, one row.
The key has to come from the source, not from n8n. A Stripe event has an event id. A form has a submission id. An email has a Message-ID. A database row can give you its id plus the time it changed. Pick one that stays the same when the event is retried.
Do not use $execution.id. It is useful for tracing, but every retry creates a new execution, so it will never catch the duplicate you care about.
Put a claim at the front of the workflow
The simplest pattern is a small table with one unique key. Postgres is a good default because the constraint does the work for you:
create table processed_events (
event_id text primary key,
received_at timestamptz not null default now(),
status text not null default 'processing'
);
At the start of the workflow, try to insert the event id:
insert into processed_events (event_id)
values ('{{ $json.event_id }}')
on conflict (event_id) do nothing
returning event_id;
If the query returns a row, this is the first time you have seen the event. Continue. If it returns nothing, stop. The second run never reaches the invoice, the email or the CRM.
After the work, update the row to done and store the id of the thing you created. That gives you a way to trace an event back to its invoice later.
[Redis] works too, with SET key NX EX 86400. The TTL keeps the store small. The tradeoff is that a key can expire while a very slow retry is still in flight, so use a window that is longer than any realistic retry.
A Google Sheet is not a lock. Two runs can read the sheet at the same time, both see no row, and both write one. It is fine for a personal workflow with one run at a time. It is not fine for invoices, payments or anything that sends email to a customer.
Handle the crash between claim and finish
The claim pattern has one weak spot. If the workflow inserts the key and then dies before doing the work, the next retry will see the key and stop. You have a row stuck in processing and no invoice.
There are two honest ways to deal with that:
- A sweeper finds rows in
processingolder than a few minutes and retries them. The work itself must still be idempotent, because the first attempt may have partly completed. - A short lock with a TTL. If the worker dies, the lock expires and the next attempt can claim it again.
For money, use the provider's own idempotency key as well. Stripe, for example, documents an [idempotency key] for exactly this reason. Your database guard and the provider's guard should agree on the same event.
Sometimes you cannot claim first
You may inherit a workflow with no event id, or the source may not provide one. In that case, check the destination before you create anything. Look for the invoice number, the contact's email, the external id, or whatever makes the record unique in that system.
This is weaker than a real claim. Two runs can still check at the same moment and both decide the record is missing. It is still better than creating blindly, and it is often the only option when the source is a spreadsheet someone edits by hand.
If the workflow has no stable key and writes to several systems, fix the key before adding more retries. More retries on a workflow with no guard just makes duplicates faster.
Respond fast, then do the work
A slow webhook is a duplicate factory. If the caller waits for your whole workflow, it may give up and retry while the first run is still going.
In n8n, use a Respond to Webhook node early, then continue the work after the response. If the work is long, put it on a queue and return immediately. The caller gets its 200, and the job runs once.
How I test a fix
A duplicate fix is not finished until it survives a replay. I test four things:
- Send the same event twice with the same id. Only one invoice or email should exist.
- Send two copies at the same time. The unique constraint should hold under concurrency.
- Stop the workflow after the first side effect, then run it again. The destination should still have one record, and the stuck claim should recover.
- Read the execution log. The second run should stop at the guard with a clear message, not fail somewhere in the middle.
I also log the event id, the execution id, the status and the destination id. A duplicate should be visible in the log, not silent. If the number of blocked duplicates jumps, the sender is retrying more often, and that is worth knowing before a customer tells you.
This is the same principle I wrote about in tools that fail loudly: make the failure visible at the boundary instead of letting it leak into the work. The evaluation post covers the test set side of the same habit.
What this saves
The duplicate cleanup I have measured gave back 2 to 4 hours a month in the first month. That is a range from real workflows, not a promise. The bigger win is not dreading the Monday invoice run.
Self-hosting n8n on your own server keeps the per-task cost low, which is one reason I like it. It also means a retry storm costs you nothing in task fees and everything in cleanup, so the guard matters more, not less.
If your workflow is sending the same thing twice, send me the execution log and the event payload. I will tell you where the duplicate enters and what to put in front of it. You can read about the rescue work, see the automation stack I build with, or [send a note].
If you want the commercial side of it, the rescue a stuck build service covers how I take on a repair.
The rescue a stuck build service covers how I take on a repair, and the pricing page explains what decides the cost.
If you want the commercial side of it, the rescue a stuck build service covers how this work is scoped and handed over, and the pricing page sets out the three engagement plans.
