
One CRM Event, Three Deliveries: How to Handle Duplicate Webhooks on AWS
Handle duplicate CRM webhook events using API Gateway, Lambda, SQS, and DynamoDB. Preserve stable event IDs, recover interrupted workers, and prevent repeated downstream actions.
Series: CRM (9 articles)
- …
- 9One CRM Event, Three Deliveries: How to Handle Duplicate Webhooks on AWS This article
To handle duplicate CRM webhooks, preserve the provider’s event ID, store the event durably before acknowledging receipt, and make processing safe to repeat. API Gateway and Lambda can receive the webhook, DynamoDB can track its state, and SQS can buffer work. Conditional updates let one worker claim an event while retries recover interrupted processing.
The difficult case happens when an external action succeeds just before the worker loses its response. That outcome needs an idempotent destination operation or a reconciliation step.
1. Start with a realistic duplicate delivery
A salesperson qualifies a lead at 10:00 a.m. The CRM sends a webhook. Your endpoint saves it successfully, but the acknowledgement reaches the CRM too late.
The provider retries the delivery. Later, the SQS worker also retries after a temporary failure.
Delivery | Stable provider event ID | Application event |
|---|---|---|
Initial webhook | evt-730 | Lead changed to QUALIFIED |
Provider retry | evt-730 | Same event |
Queue redelivery | evt-730 | Same saved event |
The application should preserve one accepted event and process its intended effect safely across all three deliveries.
A different event for the same lead must remain distinct. If the salesperson changes the lead to
NURTURE at 11:00 a.m., that is a new event with its own identity.2. Verify the webhook before accepting it
Use the CRM provider’s documented verification procedure. Providers differ in their signature headers, canonical message format, timestamp checks, and challenge requirements.
For a provider that signs the HTTP body:
- Verify against the exact bytes required by its specification.
- Apply its timestamp and replay-window rules where provided.
- Scope the event to the expected CRM workspace or tenant.
- Keep verification secrets in an appropriate secret store.
- Exclude signature headers, secrets, and full payloads from routine logs.
A successful signature establishes that the request meets that provider’s authenticity check. The application still needs to validate the event type, required fields, and destination scope.
Reject unsupported or malformed events according to the provider’s expected response behaviour.
3. Keep event identity separate from delivery identity
A provider may assign a new delivery-attempt ID every time it retries an event.
Use the stable business event identifier for deduplication when the provider supplies one. Scope it by provider and workspace:
PROVIDER#crm-demo#WORKSPACE#sales-42#EVENT#evt-730Store the delivery-attempt identifier separately for diagnostics.
If the provider offers no stable event ID, follow its documented identity rules or define a carefully scoped deterministic key. Hashing the entire request body can behave unexpectedly when irrelevant fields change between deliveries. The identity rule should distinguish retries from legitimate repeated business actions.
4. Persist before acknowledging receipt
An illustrative intake record contains:
{ "eventKey": "PROVIDER#crm-demo#WORKSPACE#sales-42#EVENT#evt-730", "status": "RECEIVED", "entityRef": "lead-208", "eventType": "LEAD_STAGE_CHANGED", "sourceRevision": 19, "attemptCount": 0, "payloadRef": "restricted-payload-reference"}Condition the initial insert on the event key being new.
If the same key already exists, compare the event’s normalized meaning with the saved record where appropriate. An identical retry can receive the provider’s expected success response. Conflicting content under the same identity should be investigated.
Return success only after the event is durably saved. The response means the integration accepted responsibility for processing it.
5. Close the gap between saving and queueing
Saving an event and sending an SQS message are separate operations. A function can stop after the first step.
Use a recoverable dispatch path. For example, a DynamoDB Streams consumer can enqueue newly received events, and a periodic reconciliation can locate received events that remain unprocessed beyond the expected window.
Queue messages can carry only the event key. The worker loads the restricted payload and current event state when needed.
Repeated dispatch can still produce duplicate queue messages, so the worker must handle them.
6. Claim work with a recoverable lease
A worker can conditionally move an event from
RECEIVED to PROCESSING and save:- A unique lease owner.
- A lease expiry.
- The next attempt number.
- The processing start time.
If another worker already holds an active lease, the competing worker should follow the retry policy.
A simplified lifecycle is:
RECEIVED → PROCESSING → COMPLETED → RETRYABLE → NEEDS_REVIEWIf the worker crashes, a recovery operation can reclaim the event after the lease expires.
Require the current lease owner when completing or updating the event. This prevents an older worker from overwriting the state after another worker has reclaimed it.
Choose the lease length in relation to expected processing time and the SQS visibility timeout. Long-running workers may need controlled extensions.
7. Protect the business effect
Suppose the event updates a lead summary and adds a history entry in DynamoDB. Those changes and the
COMPLETED status can be committed together in a transaction.An external action is different. Imagine the worker creates a sales task in another system, then stops before saving the returned task ID.
On retry:
- Use the event key as the destination’s idempotency key when supported.
- Otherwise, use a unique external reference with an atomic upsert where available.
- If the outcome is uncertain, reconcile the destination record before creating another.
- Record unresolved ambiguity for review.
A local
PROCESSING flag cannot by itself guarantee one external task across a network timeout.8. Handle out-of-order updates separately
Duplicate detection answers whether an event was already accepted. Ordering answers whether it may change the current lead.
Suppose revision 20 changes the lead to
NURTURE , then revision 19 arrives late with QUALIFIED .Preserve revision 19 for the history policy, but keep revision 20 as the current state. Use the provider’s monotonic revision where available.
If the provider only sends event timestamps, define how ties, delayed events, and corrections are handled. For an integration that mirrors current state, fetching the authoritative CRM record can be safer than blindly applying each incoming payload.
9. Retry failed batch items without replaying healthy ones
When Lambda processes messages from a standard SQS queue in batches, configure partial batch responses.
A conceptual response for one failed message is:
{ "batchItemFailures": [ { "itemIdentifier": "sqs-message-17" } ]}The identifier is the SQS message ID, while the application continues using its provider event key for deduplication.
Configure the event source mapping to support this response. A FIFO queue requires ordering-aware processing, including appropriate treatment of failed and unprocessed messages.
Send exhausted failures to a dead-letter queue with a documented review and replay process.
10. Test failure at every boundary
Failure | Expected recovery |
|---|---|
HTTP acknowledgement is lost | Provider retry finds the accepted event |
Event is saved but never queued | Reconciliation dispatches it |
Queue delivers the event twice | Conditional claim and event state prevent competing completion |
Worker stops after claiming | Expired lease allows recovery |
External task is created before a timeout | Idempotent write or reconciliation finds the existing task |
Older lead revision arrives late | Current state preserves the newer revision |
Deduplication record is removed before a delayed retry | Replay risk follows the retention policy and downstream safeguards |
Retain event identities for the provider’s retry horizon and your own manual replay requirements. If you use DynamoDB TTL for cleanup, account for its asynchronous deletion behaviour.
Frequently asked questions
Does an SQS FIFO queue remove the need for idempotency?
Keep application-level safeguards. External timeouts, manual replays, and provider retries can extend beyond a queue’s deduplication behaviour.
Can I mark an event completed before sending the external request?
That creates a gap where the event looks finished even if the request never succeeds. Record completion after the effect is confirmed or committed through an appropriate transactional design.
Should every failure be retried?
Retry temporary network and service failures with bounded backoff. Invalid mappings, unsupported payloads, and authorization failures usually need a configuration or data fix.
What should the operations dashboard show?
Show the oldest received event, expired leases, retryable failures, review cases, dead-letter messages, and ambiguous external outcomes. These point to the work still needed to complete delivery.
Implementation note — Adapt signature verification, event identity, source ordering, retention, and destination idempotency to the specific CRM provider before deployment.
Series: CRM (9 articles)
- …
- 9One CRM Event, Three Deliveries: How to Handle Duplicate Webhooks on AWS This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article