Don't let duplicate webhook events become duplicate customers
A buyer submits a form twice. A webhook is delivered again after a timeout. Then the same person emails your team.
A CRM can end up with three contacts and three separate conversations. But deleting anything that looks similar is not a solution. The same buyer might have a genuinely new opportunity, and two different people can share a name.
The more reliable approach is to separate three ideas:
- An event is an incoming form submission, webhook delivery, or email. Its external ID helps detect replays.
- A contact is a person or organization, identified by approved, reliable fields.
- A deal is a commercial opportunity. One contact can have several distinct deals.
You don't want all three concepts collapsed into one deduplication rule.
1. Make the incoming event idempotent
In an n8n workflow, the first step after receiving a webhook should be to preserve a stable event identifier and source.
For example, a database with a unique constraint can enforce:
CREATE TABLE inbound_events (
source TEXT NOT NULL,
external_id TEXT NOT NULL,
received_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (source, external_id)
);
Then an insert can safely distinguish the first delivery from a retry:
INSERT INTO inbound_events (source, external_id)
VALUES ($1, $2)
ON CONFLICT (source, external_id) DO NOTHING;
This is only the event-level idempotency gate. It does not tell you whether two inquiries belong to the same person.
Also, a find-before-create check on its own isn't race-safe: two webhooks arriving simultaneously might both see no contact and create one. Use constraints, transactions or controlled locking where your stack requires them.
2. Match contacts, not just strings
Email and phone can be useful, but matching rules need context:
- Normalize phone numbers with country codes.
- Be cautious with shared business inboxes.
- Don't merge contacts based only on names.
- Treat incomplete and conflicting matches as review candidates.
An LLM may help explain why records look related. It should not silently merge customer histories or remove data.
3. Keep a human review path
A practical n8n flow can look like this:
- Receive the event and persist its external key.
- Ignore or acknowledge previously processed technical retries.
- Search the CRM using approved contact identifiers.
- Link a confident match or create a new contact.
- Route ambiguous matches to a human.
- Create or update the deal using separate business rules.
- Log who made the decision and how errors are recovered.
The key is knowing which steps are deterministic and which steps actually need judgment.
4. Measure the pilot, not the demo
Use authorized test data and compare against a labeled sample. Track false merges, leads lost, duplicate contacts, manual reviews and processing latency.
A fast automation that loses inquiries is worse than a slightly slower one with a review step.
Full original guide: Duplicate Leads in CRM: Prevent Repeats Without Losing Inquiries.
Published originally on AI B2B Blog. This DEV Community version is a technical adaptation; the canonical URL points to the original.
Top comments (1)
I'm taking away the split of event, contact and deal into three separate identities. One thing about step 1 is worth spelling out. Say the workflow inserts into inbound_events first and then fails later, for example on a CRM timeout or a bad credential. From then on every retry of that webhook hits ON CONFLICT DO NOTHING and gets acknowledged as a duplicate. The lead is gone, which is exactly the outcome the last section warns about. A small change avoids it. Add a status column (received, processed, failed), use RETURNING or the affected row count to tell whether this delivery was new, and treat an existing row that is not yet processed as work to resume, not skip. Mark it processed only after the contact and deal steps succeed. The gate stays idempotent, and a temporary failure no longer turns into a silent loss.