Guides · duplicate delivery

Test webhook idempotency without losing valid events

A stock adjustment arrives twice. A handler that treats each delivery as a new event can record the adjustment twice. Check that the duplicate records one adjustment and a separate valid event still gets through.

Hands-on guide

Deliver the same event twice

Choose a deduplication key, then send both attempts for event A and one distinct event B. The expected local intent total is +5 units.

Stock operations Warehouse 01

Inventory / Adjustments / Item record

INVENTORY · ITEM RECORD

Adjustment queue

item_demo_001
+0units intended
Event source
source_alpha
Account
acct_one

Local outbox intents

0

No adjustments queued.

Delivery inspector

0 / 3 received

Delivery sequence

  1. 1
    evt_AFirst attempt
  2. 2
    evt_ASecond attempt
  3. 3
    evt_BDistinct event

Send the first delivery to inspect its logical event, scoped key and local handler result.

This browser model uses the first three events from the downloadable SQLite exercise. The projection counts local intents only. No inventory is updated.

Keep the event stable while attempts change

Authored local transaction · expected identity boundary

Logical event key

source + account + event_id

Keep this identity stable across retries of the same event.

Delivery attempts

Attempt A
Attempt B

Different attempt IDs carry the same logical event.

One local SQLite transaction

Inbox identity + one outbox intent

Record acceptance and the intended adjustment together.

The last box records an intended action locally. It does not send that action to an inventory system or establish an external business effect.

Your event key needs the scope that makes it unique. In this exercise, each attempt has a separate attempt ID; a resource ID can be shared by several legitimate events. Neither is automatically the right event key. The Standard Webhooks specification distinguishes a stable message identifier from changing retry timestamps. The attempt IDs and source/account fields here are authored fixture scope, not authenticated provider claims.

Check the identity policy with rejecting controls

Keep one intended action for a repeated logical event while preserving distinct events for the same resource. Compare the correct scoped event key with wrong attempt-ID and resource-ID keys, then check payload conflicts and interrupted transactions.

The duplicate-delivery example in the webhook documentation contains the Python/SQLite download, command, full control matrix and expected local ledger observations. It checks local inbox/outbox intents, not provider delivery or external exactly-once effects.

Move the assertions to your own effect boundary

  1. Define the identity and conflict policy. Derive source/account scope from trusted producer or authentication context in your real handler; the fixture envelope does not authenticate it. Name the event ID and payload comparison. Decide what changed content under the same key means; preserve the original accepted event. AWS’s idempotency guidance explains scoped identifiers and changed-intent handling.
  2. Keep the durable records together. Adapt the inbox and intended-action write to the transaction your handler actually owns. If dispatch is separate, define its idempotency and reconciliation rather than inferring them from an outbox row.
  3. Keep both rejecting controls. Duplicate attempts must not add another intended effect. Distinct legitimate events for the same resource must not disappear. Include cross-source/account and payload-conflict cases.
  4. Retain the observed evidence. Keep event/attempt identities, stored payload identity, committed intents, acknowledgement and the actual downstream result when testing a real dispatcher.

The owned child-process exits exercise local restart boundaries around SQLite’s atomic commit. The postcommit case exits only after commit returns successfully. If commit fails or never returns, the caller outcome is unknown: reopen and resolve it through the logical key. Concurrency, power loss, ordering, retention of event keys and an external dispatcher's behavior need their own tests at the relevant persistence/effect boundary.

Add HTTP only for the callback path you need

An in-process consumer test can answer the local identity question. The download does not expose an HTTP receiver; provide your own safe test endpoint if you add replay. To deliver a selected UTF-8 callback over HTTP, Gostly can retain a capture and manually replay its stored text to an approved, API-reachable test receiver. Follow the capture-versus-replay boundary and the explicit replay instructions.

A Gostly capture ID identifies the retained delivery record, not your consumer's logical event. Replaying the same stored capture can reuse that capture ID; your test driver owns any separate attempt identity. Confirm the actual target response and durable application result. Replay does not add the consumer transaction or deduplication policy shown here.

Resources

Continue at the boundary your test needs

Replay a selected HTTP capture deliberately

Use the documented stored-text, header, target and delivery-result contract.

Read webhook replay

Decide what an uncertain write permits

Keep retry permission separate from a timeout or failed response.

Read retry testing

Review retained event data

Choose safe inputs, stores, access and destinations for the real test.

Use the data worksheet

Keep the local assertion when you add HTTP.

If the next test needs Gostly's HTTP path, use the supported Pro setup and an approved test receiver. Optional Team MCP management is separate from the consumer exercise.

Continue to Pro HTTP setup