December 2, 2026 · Developer Experience

Webhook Delivery: Retries, Idempotency and the Receiver’s Point of View

A blue event packet reaches a translucent gateway while a faint duplicate path joins the same amber processing node.

A webhook is often introduced as a small convenience: when something changes, send a request to a URL. The receiver’s experience is less tidy. Requests arrive while a deploy is in progress, a database is slow, an event appears twice, or a handler finishes its work just before the connection drops. From the sender’s point of view, the outcome is uncertain. From the receiver’s point of view, the same delivery may be both urgent and already in progress.

Reliable webhook integration depends on treating delivery as a protocol between two independent systems. The sender can make an attempt; the receiver must decide whether it is authentic, whether it has already processed the event, what work belongs in the request path, and when it is safe to acknowledge receipt. Retries help with temporary failures, but they do not remove ambiguity. Idempotent processing, durable queues and clear event contracts are what make that ambiguity manageable.

Start with the receiver’s failure model

Imagine that a payment provider sends an event saying a subscription changed. The receiver verifies the request, writes an update to its database and returns a success status. If the response is lost after the write commits, the sender cannot know whether the operation succeeded. It may retry. A receiver that assumes one request equals one unique event can then repeat an email, create a duplicate invoice or grant access twice.

The reverse failure is equally important. If the receiver returns success before saving enough information to resume the work, a process crash can lose the event even though the sender reasonably believes it was accepted. A useful design therefore asks two questions separately: when may the receiver tell the sender “I have this,” and when is the downstream business effect complete? Those moments do not have to be the same.

Define the delivery contract before writing the handler. What status codes mean accepted? Which failures should trigger another attempt? How long can processing take? Are events snapshots of an object or notifications that say “fetch the current state”? Can events arrive out of order? How long may an event be retried? Providers differ, so the contract should be derived from the specific service’s current documentation rather than from a generic assumption about webhooks.

Authenticate the exact request

A public endpoint should assume that anyone can send it traffic. Do not trust a JSON body because it contains a familiar event name or account identifier. Verify the provider’s signature using the provider’s supported library or documented algorithm. In signature schemes that cover the raw request body, preserve the original bytes: parsing JSON and serializing it again can change whitespace or character escaping and make a valid signature impossible to reproduce.

Use the signing secret associated with the correct endpoint and environment. Keep test and live secrets separate, load them from a secret manager or protected runtime configuration, and make rotation an operational task with an owner. If a provider supports overlapping secrets during rotation, document how each is introduced and removed. Never place a secret in a client-side bundle, a screenshot, a public repository or diagnostic output.

Check timestamp tolerance when the provider’s signature scheme includes a signed timestamp. This can limit acceptance of old captured requests, but it is not a substitute for deduplication: legitimate retries may also be recent, and a valid signed delivery can still be repeated. Avoid logging the full signature header or raw body by default. When debugging, record a delivery identifier, endpoint, verification outcome and a carefully redacted summary.

Signature verification answers a narrow question: whether the message matches the expected signing process and has not been altered in transit in a way the signature detects. It does not prove the business action is safe, current or appropriate. After verification, validate the event type, account or tenant, object identity and expected state before applying effects.

Separate receipt from business processing

A webhook request handler should do the minimum work needed to make the event durable and safe to process. A common pattern is to verify the signature, validate a small envelope, write the event identifier and payload reference to a durable inbox or queue, then return the provider’s expected success response. A worker performs slower tasks such as updating several records, sending mail, syncing another service or generating a report.

This boundary shortens the time the sender waits and reduces the chance that a temporary downstream outage turns into a storm of retries. It also introduces a new responsibility: the handoff to the queue must itself be durable. If the handler acknowledges an event before the queue write commits, there is a gap in which the event can disappear. Use a transactional insert, a message broker acknowledgement or another mechanism whose failure behavior is understood.

For a small system, a database table can serve as an inbox: store a unique event ID, event type, received timestamp, processing state, attempt count and a payload reference. A worker claims pending rows, performs the work and records completion or a retryable failure. The exact storage design depends on throughput and operations; the principle is that acceptance should leave a recoverable record rather than an in-memory promise.

Do not make the HTTP response imply that every downstream action is complete if it only means that the event has been durably accepted. Name the internal states clearly: received, queued, processing, completed, rejected or awaiting review. Those states help support staff distinguish “the sender did not reach us” from “we accepted it but our worker is behind.”

Make effects idempotent

Idempotency means that repeating the same logical operation does not produce an additional business effect. It is a design property of the receiver, not a guarantee that the sender will never repeat a request. The IETF’s HTTP semantics describe idempotent methods in terms of the intended effect of repeating a request, and caution against automatically retrying a non-idempotent request without a way to know whether the original was applied. Webhook POST requests commonly represent application events, so the receiver should provide its own safe repeat behavior.

Start by identifying the provider’s stable event ID. Place a uniqueness constraint on the inbox record, scoped to the provider account or endpoint when identifiers are not globally unique. If the same event ID arrives again, do not enqueue a second independent business action. Return the response the provider expects for a successfully handled duplicate, while retaining enough metadata to observe how often duplicates occur.

An event ID alone may not cover every semantic duplicate. Some providers can emit distinct event objects that refer to the same underlying change. If the business action must happen once per object transition, define a domain key, such as an object identifier plus transition or version. Do not invent a key by concatenating convenient fields unless the combination is guaranteed to identify the operation. A weak key can suppress legitimate changes or allow duplicates through.

Protect the effect as well as the inbox. If a worker writes an order update and then crashes before marking the event complete, the job may run again. A database transaction can make the state change and completion marker atomic when they share a database. For an external side effect, use that service’s idempotency feature if available, or record a stable operation key and reconcile uncertain outcomes before retrying. There is no universal transaction across unrelated providers.

Assume ordering is not guaranteed

Events are often delivered asynchronously and can be delayed, retried or processed through parallel workers. An “account created” notification might arrive after an “account updated” notification, or the update may be retried after a newer change has already been applied. A receiver that blindly overwrites current state with whichever payload arrives last can move the record backward.

When the provider includes an object version, sequence number or trustworthy update time, compare it with the state already stored and reject stale transitions according to documented rules. A timestamp alone can be an imperfect ordering key if clocks or event generation semantics differ. If the event is only a trigger and the provider offers a safe API to retrieve the current object, fetching current state may simplify convergence. It also adds latency, rate-limit pressure and a dependency on API availability.

Do not assume that event names form a complete history. Some systems send snapshots, some send compact change notifications, and some group several changes. Read the provider’s payload definition and versioning policy. For a snapshot, decide which fields the application owns and which fields should be overwritten. For a notification, handle the possibility that the object has changed again before the receiver fetches it.

Retry with backoff, not a tight loop

Retries are useful for transient failures such as a brief network problem or a worker dependency recovering. A retry policy needs bounds: maximum attempts or age, delay growth, jitter to spread concurrent retries, and a final destination for unresolved work. A fixed short interval can make an outage worse because many deliveries synchronize and hit the recovering service together.

Classify failures. A temporary database connection failure may be retryable. A signature mismatch, unknown account or invalid event schema usually needs investigation rather than repeated identical attempts. Some errors depend on a later configuration change, so a manual replay may be appropriate after correction. Record why an event is parked and who can release it, instead of silently discarding it or retrying forever.

Provider behavior is not fully under receiver control. The sender may have its own schedule, maximum retry period, manual replay tools and rules for which response codes count as success. Learn these details for the specific integration. Stripe’s current webhook guidance describes automatic retries and manual resending for its event destinations; those rules are specific to Stripe and can differ across event types or delivery configuration.

Do not use a successful HTTP status to hide a permanent processing failure unless the event has been durably moved to a dead-letter or review queue. If the receiver returns success after losing the event, the sender may stop retrying. Conversely, returning an error while a durable worker will certainly process the event can create unnecessary duplicate delivery attempts. Align the acknowledgement rule with the durability boundary.

Keep the endpoint small and observable

Network handlers need limits. Define accepted methods and content types, set a maximum body size, and protect the endpoint against resource exhaustion. Rate limits should account for legitimate bursts and provider retry patterns. A reverse proxy or firewall can help with connection controls, but it should preserve request details required for signature verification.

Collect operational measurements that answer practical questions: request rate, signature failures, accepted events, duplicates, queue depth, age of the oldest pending event, processing duration, retry count and terminal failures. Add a correlation identifier that follows an event from HTTP receipt through worker processing and downstream calls. Avoid logging secrets or unnecessarily large payloads, and define retention for the diagnostic records.

Monitor both delivery and processing. A healthy endpoint can accept events while the queue worker is stopped. A healthy worker can process the queue while new requests fail at the edge. Alerts should distinguish these cases, name the affected integration and point to the next diagnostic view. A single “webhook failed” alert is usually too vague to guide a response.

Make replay deliberate. A safe replay tool should identify the original event, show its processing history, allow an operator to preview the planned action and prevent accidental duplicate side effects. If a code fix changes behavior, replay into a controlled test environment first when possible. Preserve a record of who initiated replay, why, and which result followed.

Test the ambiguous cases

A happy-path test proves little about delivery reliability. Test a repeated event ID, two distinct events for one object, out-of-order delivery, malformed payloads, invalid signatures, delayed processing, queue unavailability and a worker crash after the external effect but before the completion record. For each scenario, write down what the sender sees, what the inbox stores and whether the business effect happens zero, one or multiple times.

Use provider tooling or signed fixtures for local testing rather than disabling signature verification in the normal code path. Keep test secrets isolated and make it hard to accidentally point a development process at a production endpoint. Test payloads should cover fields that may be absent or null, events your application does not subscribe to, and schema versions that the provider documents as supported.

Review failure recovery with the people who will operate it. Can they find the event by ID? Can they tell whether a side effect may already have happened? Can they retry one event without replaying a whole time range? Is there a clear action when the provider’s own retry window has expired? A system that works only when the original engineer is present has an operational gap.

Document the integration as a contract

For every webhook integration, document the subscribed event types, source account, signing-secret ownership, event-ID semantics, acknowledgement rule, retry behavior, processing states, data retention and replay procedure. Include payload examples with fake data that is clearly labeled as illustrative. Describe which fields the application relies on and what happens when the provider adds an optional field.

Keep that document close to the code that consumes the event. When a handler changes, update its tests and its operational notes in the same review. Version internal event models when meaning changes; a field name that looks stable can still acquire different semantics as a provider evolves its API. A compatibility layer can let the rest of the application work with a normalized internal representation while adapters handle provider-specific versions.

Be precise in product and security claims. “We support webhook notifications” does not explain delivery guarantees, ordering, retention or replay. Do not promise exactly-once delivery unless the whole chain can establish that property under the failures you support. In many systems, a more accurate description is at-least-once attempts with deduplicated business effects and an operational recovery path. State the boundaries that matter to the customer.

Make uncertainty visible and recoverable

A webhook integration is dependable when a duplicate does not repeat an important action, an uncertain outcome can be reconciled, and a delayed event can be recovered without guesswork. That usually means authenticating the original request, writing a durable receipt, separating acceptance from processing, making effects idempotent and treating ordering as a design question.

Begin with the failure that would matter most to the product: an access grant applied twice, a cancellation missed, a shipment state moved backward, or a customer notification sent repeatedly. Trace that case from sender to receiver and back. Then build the smallest durable boundary, replay path and monitoring signal that make the outcome understandable. Those details—not the presence of an endpoint alone—turn a webhook into a reliable integration.

Primary references

Read the provider’s live documentation for its current delivery contract. Stripe’s webhook documentation covers endpoint setup, signature verification, retries, duplicate events and event ordering for Stripe integrations. The IETF HTTP Semantics specification (RFC 9110) defines idempotent request semantics and explains why retrying a non-idempotent operation requires care. These references describe protocol behavior; the receiver still has to define its own business-level deduplication and recovery policy.

Leave a comment

Your email address will not be published. Required fields are marked *