The Webhook Arrived Twice: Deduplicating Webhook Deliveries in n8n
Описание и применение
Webhook‑поставщики могут доставлять одно и то же событие несколько раз, что приводит к дублированию действий. Быстрый ответ, атомарное вставление с уникальным ключом события, проверка подписи и идемпотентность последующих действий позволяют избежать дублирования.
Задача
Webhook providers may deliver the same event multiple times, causing duplicate downstream actions such as duplicate emails or records.
Результат
Implementing fast acknowledgment, atomic deduplication on provider event ID, signature verification, and downstream idempotency prevents duplicate processing and ensures reliable webhook handling.
Рабочий процесс
- 1. Receive webhook request in n8n.
- 2. Verify provider signature on raw body; if invalid, log and return 200.
- 3. Extract provider event ID (or build natural key).
- 4. Attempt atomic insert into deduplication table with unique constraint; if insert fails, return 200 and exit.
- 5. Record event metadata and return 200 to acknowledge receipt.
- 6. Trigger a second workflow or later stage to perform heavy processing (LLM calls, writes, email).
- 7. Ensure downstream actions are idempotent (upserts, deterministic message IDs).
Доказательства
A workflow I ran for months listened for a provider webhook: a payment event, a form submission, a status change. One day a customer got two confirmation emails, and a downstream record was created twice.
The first mistake is doing slow work inside the webhook handler. The provider waits for your response; if your workflow takes thirty seconds to call an LLM, write to three systems, and send an email, the provider's timeout fires first and it redelivers — creating the very duplicate you were trying to avoid.
Rule 2: dedup on the provider's event id, never on arrival time
Rule 3: verify the signature before you trust the payload
Rule 4: make the downstream work safe to run twice anyway
The checklist I actually use ... Webhook handler validates, records, and returns 200 fast; slow work runs in a second stage.
- Дата записи: 2026-11-01T03:43:50.772Z