A webhook receiver should expect uncertainty. The sender may retry after a timeout, events may arrive after the resource has changed again, and two deliveries may reach different application instances at the same time. Reliable processing begins by separating receipt of the message from the business effect it is intended to trigger.
Stripe’s webhook documentation documents duplicate deliveries, signature verification and event-handling considerations for its platform. Those details are provider-specific, but they illustrate the questions every integration must answer. Use the sender’s current documentation for exact delivery guarantees and verification procedures rather than assuming all webhook systems behave alike.
Define what the event means to your application
Identify the business fact represented by the event and the action your system should take. A notification that a subscription changed may require updating local state; it does not necessarily require sending an email for every delivery.
For a fictional membership application, distinguish the provider’s event from the member’s current entitlement. The event is evidence that something happened at a particular point. The application must decide whether to use the included data, retrieve current state or apply a versioned transition.
Document which event types the receiver supports. Unknown types should have a deliberate, observable handling policy. A broad endpoint that accepts everything without recording its interpretation makes later debugging difficult and can hide an integration that stopped processing a newly relevant event.
Authenticate the delivery before trusting its content
Follow the provider’s documented signature-verification method, including its treatment of the raw request body and timing. Parsing and reserializing a body before verification can change the bytes involved, so use the supported library or procedure for the actual framework.
Keep the verification secret in the approved secret-management system. Do not copy it into logs, example requests or a repository. Distinguish test and production endpoints and credentials so a development setup cannot accidentally be treated as a production sender.
Verification establishes that the delivery satisfies the provider’s authenticity mechanism. It does not remove the need to validate the event’s shape, account context and supported semantics. Continue to treat the payload as input at an integration boundary.
Record receipt before expensive processing
Keep the receiving path bounded. After authenticating and validating enough to accept the event, persist the information needed for durable processing. Then acknowledge according to the provider’s contract when acceptance is safely recorded.
Do not acknowledge merely because a background task was started in the memory of a process that may exit. If the response tells the sender the delivery was accepted, the application needs a credible way to continue after a crash.
Conversely, avoid performing every slow business operation before acknowledging when the sender’s timeout and retry behavior make that risky. A durable inbox or equivalent mechanism can separate network delivery from processing while preserving the event’s identity and status.
Choose a deduplication identity
Use the provider’s documented event identifier where appropriate, scoped to the relevant provider account or environment. Record it under a uniqueness constraint or another atomic mechanism. A check followed by an unprotected insert can race when duplicates arrive concurrently.
Consider whether distinct events can represent the same business transition. Deduplicating exact event identifiers prevents repeated processing of one event, but it may not prevent two separate events from triggering the same side effect. The application may need a second business-level identity for actions such as sending one confirmation.
Do not build the identity from unstable fields or an entire serialized payload without understanding the consequences. A harmless metadata difference can produce a different hash, while an overly broad key can suppress legitimate later work. Identity should reflect the specific effect being protected.
Track processing state explicitly
A receipt record needs more than a seen flag. Distinguish accepted, processing, completed and failed states, along with attempts and relevant timestamps. Otherwise a crash after marking an event seen can cause future deliveries to be ignored even though the business action never finished.
Define which worker may claim the event and how abandoned work becomes eligible for recovery. Use the storage system’s supported concurrency mechanism and test the actual race conditions. A status field alone does not enforce exclusive processing.
Store bounded error context for failed attempts. Operators need to know whether the problem is invalid data, a temporary dependency failure or a defect in the handler. Keep private payloads and credentials out of ordinary logs while preserving controlled access to evidence required for investigation.
Make the business effect repeat-safe
Each consequential action needs a way to avoid uncontrolled duplication. Updating a local state to a known value differs from incrementing a balance or sending a message. Review the actual operation rather than assuming all handlers are naturally idempotent.
For the membership example, granting access based on the provider’s current subscription state can be designed differently from adding one month of access every time an event arrives. The latter can produce a clear duplicate effect unless the transition is tracked.
When the handler calls another external service, use that service’s supported idempotency mechanism when available and appropriate. Preserve the mapping between the incoming event and the outgoing action so recovery can identify what may already have happened after a timeout.
Handle out-of-order events deliberately
Read the sender’s ordering guarantees and design for the documented behavior. An older event arriving after a newer one can overwrite current state if the handler blindly applies payloads in arrival order.
Choose an approach suited to the domain. The application might retrieve the current resource state, compare a reliable version or process an ordered sequence when the provider supports one. Each choice has tradeoffs involving extra calls, rate limits and the meaning of historical events.
Do not use receipt time as a substitute for event order. It describes when your endpoint received the message, not necessarily when the underlying change occurred. Preserve relevant provider timestamps and identifiers, but use them only according to their documented semantics.
Separate retry policy from provider redelivery
Your worker retries and the sender’s delivery retries are different mechanisms. The sender may deliver again because it did not observe an acknowledgment, even while your internal worker is processing the first receipt. Deduplication and state handling must keep those paths coherent.
Classify failures before retrying. A temporary outage may justify another attempt; an unsupported payload or missing required mapping may require review. Repeatedly retrying a permanent error can consume resources without increasing the chance of success.
Define an exhausted-retry path with an owner. A failed-event queue is useful only if someone can inspect, correct and replay the event safely. Record the procedure and the evidence required before replay, especially when part of the business action may already have occurred.
Build an operator-friendly replay process
A replay should preserve the event’s identity and audit trail. It should not bypass duplicate protection by silently inventing a new identifier. The operator needs to understand whether the action resumes failed work, re-evaluates current state or deliberately performs a new operation.
Provide a dry diagnostic view where practical: event type, account scope, previous attempts, current state and the planned handler. Avoid exposing the full private payload to people who only need operational status.
Record who initiated a manual replay and why. If a code fix changes how an old event is interpreted, connect the replay to that change. This makes later investigation possible without relying on memory of an emergency session.
Test delivery and processing failures separately
Use the provider’s supported test tools or synthetic fixtures to exercise signature validation, malformed input and duplicate delivery. Include two simultaneous copies, not only sequential retries. Verify that the durable receipt and final business state match the intended contract.
Simulate a worker stopping before the side effect, after the side effect and before marking completion. These boundaries reveal whether recovery can safely resume. A handler that works only when every step completes in one uninterrupted run is not ready for ordinary production failures.
Test out-of-order events and events for deleted or inaccessible local resources. The handler should produce a documented outcome rather than an endless retry loop. Keep test credentials and test customer data separate from production throughout the exercise.
Monitor outcomes, not just endpoint responses
A low webhook HTTP error rate can coexist with a growing internal failure queue. Track accepted events, completed business actions, processing delay and terminal failures. Connect these signals through the event identity without logging unnecessary sensitive content.
Alert on conditions that require action, such as old unprocessed events or a sudden change in failure categories. Include the relevant integration and runbook. A raw count of incoming messages is useful context but does not prove the integration is fulfilling its purpose.
The receiver is dependable when duplicate and delayed delivery are ordinary handled conditions. Authentic receipt, durable state, repeat-safe effects and observable recovery work together; none of them alone is a complete webhook design.
Continue reading
Make Database Migrations Compatible with Rolling Deployments
Test a Third-Party Integration Without Depending on Production