What Is a Webhook? An Interactive Example With a Retry
A webhook is an HTTP request one system sends to your URL when an event happens. Follow a simulated delivery, failure and retry, and sign a payload.
A webhook is an HTTP request that a service sends to your URL when something happens, such as “order paid”. Instead of your code repeatedly asking “has anything changed?”, the other system tells you, usually with a POST whose JSON body describes the event. Your endpoint must reply quickly with a 2xx status, verify the request’s signature, and cope with retries and duplicates.
A delivery, step by step
SimulatedThis timeline is an illustrative delivery, not a recording from a real provider. The behaviours it shows (2xx means success, failures are retried, retries can create duplicates) are documented by Stripe and GitHub.
-
10:00:00Step 1. Event happens at the provider
A customer pays order ord_42. The payment provider creates event evt_1001 of type order.paid.
{"id":"evt_1001","type":"order.paid","order_id":"ord_42","amount":2599} -
10:00:01Step 2. Provider POSTs to your endpoint
It sends the JSON body to https://shop.example/webhooks with a signature header computed from the raw body and a shared secret.
POST /webhooks HTTP/1.1 Content-Type: application/json X-Signature: sha256=… -
10:00:31Step 3. Attempt 1 fails
Your server is mid-deploy and returns 503 after 30 seconds. Any non-2xx status, a timeout or even a redirect counts as a failed delivery.
HTTP/1.1 503 Service Unavailable -
10:01:31Step 4. Attempt 2: retried with backoff
The provider waits and tries again. Real schedules back off over hours or days; Stripe documents up to three days in live mode.
-
10:01:31Step 5. Your endpoint verifies and acknowledges
It recomputes the HMAC over the raw body, compares it with the header, stores evt_1001 in a processed-events table, queues the fulfilment job and returns 200 immediately.
HTTP/1.1 200 OK -
10:01:40Step 6. A duplicate arrives
Because of a network hiccup, evt_1001 is delivered again. Your handler finds the ID already recorded, returns 200 and does nothing else, so the order is not shipped twice.
What a webhook request contains
- Method and URL: almost always
POSTto an HTTPS endpoint you registered with the provider. - Body: JSON describing the event, with a unique event ID and a type such as
order.paid. Some providers send the full object (“snapshot”), others a thin notice you then fetch with the API. - Signature header: an HMAC of the body (often plus a timestamp) using a secret only you and the provider know. Stripe uses
Stripe-Signature; GitHub usesX-Hub-Signature-256.
Verify the signature
Anyone can POST to a public URL, so the signature is what proves the request came from the provider and was not altered. Compute HMAC-SHA256 of the raw body with the shared secret and compare it with the header in constant time. Change one character of the body below and the signature changes completely.
- Computed HMAC-SHA256
X-Signature: sha256=7510ec97ee136627f856ee5943e8c1b330dbb5ff4626797b66f2ce9aab9eb84eChange one character of the body and the signature changes completely. Sign and verify the raw bytes, before any JSON re-formatting.
Two details trip people up. Verify the bytes exactly as received, before any JSON parsing or reformatting, because re-serialized JSON rarely matches byte for byte. And reject old timestamps if the provider signs one, to stop someone replaying a captured request.
Handle retries, duplicates and order
Providers retry failed deliveries, so the same event can arrive more than once, and events can arrive out of order: Stripe states it does not guarantee delivery order. Design for it:
- Acknowledge fast. Return
2xxas soon as the request is verified and stored; do slow work in a background job. Slow handlers time out and trigger retries. - Deduplicate by event ID. Record processed IDs and skip repeats. This makes the handler idempotent: processing an event twice has the same effect as once.
- Do not rely on order. If
order.shippedarrives beforeorder.paid, fetch the current state from the API instead of assuming a sequence. - Don’t redirect. Point the provider at the final URL; a 301 or 302 is treated as a failed delivery.
When to use webhooks
Webhooks shine when events are infrequent and you want to react quickly: payments, form submissions, repository pushes, shipment updates. The alternative is polling the provider’s API on a schedule. The webhook vs. API comparison counts the requests each approach needs for the same order flow. Webhook endpoints typically authenticate the sender by signature, while your calls back to the provider authenticate you with a key, covered in what an API key is.
Sources
- Receive Stripe events in your webhook endpoint — Stripe Docs. retries for up to three days in live mode; duplicates; no ordering guarantee
- Validating webhook deliveries — GitHub Docs
- RFC 2104: HMAC: Keyed-Hashing for Message Authentication — IETF
How we made this
Illustrative sample data. The delivery timeline is a labeled simulation, not a recording from a provider. The HMAC-SHA256 signing calculator runs WebCrypto in your browser; its output for the default payload was checked against Node.js crypto.createHmac. Retry, ordering and duplicate behaviour are cited from Stripe's and GitHub's webhook documentation.
Performed by Claude, an AI assistant working in the BinConvert repository (Node.js 25 (crypto), browser WebCrypto), November 16, 2026.
This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; the default signature was recomputed with Node.js and the provider behaviours were checked against current documentation. Review: automated test suite and source check, November 16, 2026.
Spotted an error? Tell us and we will correct it.