n8n Webhook Runs Twice? How to Stop Duplicate Shopify Orders, Emails and Refunds
One Shopify order, two executions in n8n. Sometimes it's harmless, just a second log line. Sometimes it's two "your order shipped" emails, two rows in your CRM, or, worst case, two refunds. This happens to n8n users regularly, and in most cases neither n8n nor Shopify is broken. Webhooks are built to be delivered more than once.
This checklist covers Shopify webhooks in n8n, but the same steps apply to Stripe, Lemon Squeezy, Gumroad and most other webhook senders.
Why the same event arrives twice
- Shopify can redeliver. Shopify's webhook docs: "Shopify minimizes duplicate deliveries, but your app might receive the same webhook more than once, for example after a network timeout or a retry."
- Slow responses count as failures. "Your app must respond to the webhook within five seconds." A delivery that doesn't get a 2xx in time fails and is retried. Shopify "retries failed webhook calls up to eight times in a four-hour period", and if failures continue, it removes the subscription.
- Two subscriptions, two deliveries. If more than one subscription exists for the same topic, each gets its own delivery.
- n8n retries. A node with Retry On Fail reruns after an error. If the first request actually succeeded and only the response was lost, the retry repeats the side effect.
So the target is not "make sure it only runs once". It is: running it twice must have the same effect as running it once.
Quick reference
- Respond to Shopify quickly, before slow work.
- Pick the right dedupe key:
X-Shopify-Webhook-Idper delivery, or a business ID (order ID + action). - First layer: the Remove Duplicates node with "Remove Items Processed in Previous Executions".
- Second layer, before any irreversible step: claim the key with an atomic insert.
- Pass an idempotency key to APIs that support one.
- Keep Retry On Fail off on nodes that create, charge, refund or send.
- Test with a replay and with two concurrent copies.
☐ 1. Respond within Shopify's 5 seconds
n8n's Webhook node has these Respond modes:
- Immediately: returns the response code and the message "Workflow got started".
- When Last Node Finishes: waits for the whole workflow and returns the last node's output.
- Using 'Respond to Webhook' Node: responds wherever you put that node.
If the workflow calls an AI model, a store API or a mail service before it responds, it can easily take more than 5 seconds, and Shopify will retry. Respond first: use Immediately, or put Respond to Webhook right after the trigger and any signature check. Then do the slow work.
Note: in one n8n community thread, several users reported two executions for every webhook call. One of them said it stopped after switching the respond mode from "Immediately" to "When Last Node Finishes". No cause was confirmed in that thread. If you see an exact 2× on every call (not occasional duplicates), check for a second active workflow or a second subscription with the same path before changing modes.
☐ 2. Choose the dedupe key
Shopify's docs name the header to use: "use the X-Shopify-Webhook-Id header to detect and skip duplicates". They also say that with multiple subscriptions for one topic, each delivery "has a different X-Shopify-Webhook-Id but shares the same X-Shopify-Event-Id". Use the Webhook ID to drop repeated deliveries and the Event ID to group deliveries of the same merchant action.
In a Webhook node, request headers are in the output, so you can reference them as {{ $json.headers["x-shopify-webhook-id"] }}.
Note: header names usually arrive in lower case in n8n's webhook output. Check one real execution before you write the expression. The dedicated Shopify Trigger node may not output request headers. In that case use a business key.
Business keys describe what should happen only once, for example orders-create:<order id> or refund:<order id>:<approval id>. For orders/create, the order ID is a natural key, because an order is only created once. For a refund, tie the key to the refund decision, not just the order. An order can legitimately get two partial refunds.
Never build the key from $execution.id, $now or a random UUID. Every run gets a new value, so nothing is ever recognised as a duplicate.
☐ 3. First layer: Remove Duplicates across executions
The Remove Duplicates node can remember items between runs. Its docs describe the version overhauled in n8n 1.64.0; on older versions, check the previous docs.
- Operation: Remove Items Processed in Previous Executions
- Keep Items Where: Value Is New
- Value to Dedupe On: your key from step 2
- Scope: Node (default) or Workflow
- History Size: the number of items to remember. The default is 10,000.
Put it right after the trigger (and after the respond step). A redelivered webhook then stops there with no output. Clear Deduplication History resets the memory if you need to reprocess.
Note: this is a good filter for deliveries that arrive seconds or minutes apart. n8n community answers point out that the check isn't atomic, so two copies arriving at the same instant can both pass. The n8n docs don't address concurrency either way. Treat the node as a filter, not as the guarantee for money-moving steps.
☐ 4. Second layer: claim the key atomically before side effects
For anything you can't undo (refunds, charges, inventory changes, sending to a customer), claim the key in a database with a unique constraint:
CREATE TABLE IF NOT EXISTS processed_actions (
action_key text PRIMARY KEY,
status text NOT NULL DEFAULT 'pending',
created_at timestamptz NOT NULL DEFAULT now()
);
INSERT INTO processed_actions (action_key)
VALUES ($1)
ON CONFLICT DO NOTHING
RETURNING action_key;
In PostgreSQL, ON CONFLICT DO NOTHING "simply avoids inserting a row", and RETURNING returns values only for rows "actually inserted". In n8n:
- Postgres node runs the insert with your key as the parameter.
- IF node: did it return a row? - Yes: this execution owns the action. Continue. - No: another execution already claimed it. Stop, successfully. It is not an error.
- After the side effect succeeds, update
statustodone.
If a run dies between the claim and the side effect, the row stays pending. Before retrying a pending key, check on the provider's side whether the action already happened, instead of blindly sending it again.
☐ 5. Pass an idempotency key to APIs that accept one
Some APIs deduplicate for you. Stripe documents an Idempotency-Key request header: retries with the same key return the saved response. In an HTTP Request node, send your business key from step 2 in that header. Check your provider's docs. Not every API supports idempotency keys, and not every operation within an API does.
☐ 6. Keep Retry On Fail away from side effects
n8n's node settings describe Retry On Fail as: "When an execution fails, the node reruns until it succeeds." That's fine for reads. For a POST that creates, charges, refunds or sends, a timeout doesn't tell you whether the first attempt went through.
- Turn Retry On Fail off on those nodes, or
- Keep it on only when the request carries an idempotency key the API honours (step 5), or the action is protected by the claim from step 4.
☐ 7. Test it on purpose
Before trusting a workflow that moves money or messages customers:
| Test | Expected |
|---|---|
| Send one event | One action |
| Replay the same event | No new action; execution ends successfully |
| Send two copies at the same time | Exactly one action |
| Same order, a genuinely new event (for example a second partial refund) | Processed as new |
| Kill the run after the side effect, then retry | No second action |
To replay, send a payload you captured from a real execution to your webhook URL again (for example with curl). For the concurrency test, start two of those requests at the same moment. Use a development store and test-mode credentials for anything that moves money.
Symptom table
| Symptom | Likely cause | Fix |
|---|---|---|
| Occasional double execution for one order | Shopify redelivery after a slow or failed response | Respond fast (1) + dedupe (2–3) |
| Exactly 2 executions for every call | Duplicate subscription or active workflow; see the Note in step 1 | Check registrations; dedupe anyway |
| Duplicate passes Remove Duplicates | Two copies arrived concurrently | Atomic claim (4) |
| Charged or refunded twice after a timeout | Retry On Fail on a POST | Idempotency key (5) / retry off (6) |
| Dedupe never triggers | Key built from execution ID or time | Key from the event or business ID (2) |
If you're building store support or refunds in n8n
The Store Support Agent Pack for n8n is a pack of 8 n8n workflow JSON files for online stores that you import into your own n8n. Its Refunds scenario ($39 per scenario, $79 for all 8) builds these guards into refund triage, risk check and execution. According to its product page, refunds use idempotency keys, per-order locking and a store-side "already refunded" check. In its workflow tests (against the bundled mock store), resending a request, or sending 10 at the same time, still created exactly one refund. Refunds only run when you call workflow 08 with decision set to approve, and the docs ask for one Idempotency-Key per refund decision. Invalid model output or API errors get one corrective retry and then go to a human; no money moves on bad output.
It works with Shopify through an included adapter for the Admin GraphQL API. The page says the adapter was unit-tested against simulated Shopify responses, not a live store, and recommends a $1 refund on a development store first. Other stores connect through 6 documented endpoints. Any OpenAI-compatible model works. The workflows were tested on n8n 1.123.84, self-hosted and in a Cloud-style setup.
Sources
- Shopify, Verify webhook deliveries (ignoring duplicates, X-Shopify-Webhook-Id vs X-Shopify-Event-Id): https://shopify.dev/docs/apps/build/webhooks/ignore-duplicates
- Shopify, Troubleshoot webhooks (5-second response, 8 retries in 4 hours): https://shopify.dev/docs/apps/build/webhooks/troubleshooting-webhooks
- n8n Docs, Webhook node (Respond modes): https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/
- n8n Docs, Remove Duplicates node: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.removeduplicates/
- n8n Docs, Node settings (Retry On Fail): https://docs.n8n.io/workflows/components/nodes/
- PostgreSQL, INSERT (ON CONFLICT, RETURNING): https://www.postgresql.org/docs/current/sql-insert.html
- Stripe API, Idempotent requests: https://docs.stripe.com/api/idempotent_requests
- n8n Community, "How to deduplicate Shopify "orders/create" webhook triggers in n8n": https://community.n8n.io/t/how-to-deduplicate-shopify-orders-create-webhook-triggers-in-n8n-occasional-duplicate-firings/314083
- n8n Community, "Webhook receiving duplicate executions, doubling execution count": https://community.n8n.io/t/webhook-receiving-duplicate-executions-doubling-execution-count/197126