Almost every integration with payments, an online store, Git or a CRM goes through webhooks. And almost every integration bug I've had to dig into went through them too: the order released twice, the status that went backwards, the event that "never arrived" because the endpoint took 11 seconds to answer.
The concept is simple. The details are where the trouble lives. This article explains what a webhook is, compares it with the alternatives people usually mix it up with (polling, long polling, WebSocket, SSE and queues), takes apart the myths and shows how to receive and send them the way Stripe, GitHub, Shopify, Mercado Pago and Asaas document it. Everything checked on November 21, 2026.

What a Webhook Is
Say you want to know when a Pix payment (Pix is Brazil's instant payment system) went through. There are two ways:
- Ask: every 30 seconds, your system calls the gateway's APIContract that defines how one program asks another for data or actions: which endpoints to call, what to send and what comes back. On the web, usually HTTP with JSON. and asks "so, did it pay?". Most of the time, the answer is "not yet".
- Get told: you register a URL with the gateway, and it sends a
POSTto it the moment the payment clears.
The second one is the webhook. Technically, it's just a regular HTTP request, made by the system that has the event to the system that wants to know about it.
POST /webhooks/payments HTTP/1.1
Content-Type: application/json
webhook-id: msg_2KWPBgLlAfxdpx2AI54pPJ85f4W
webhook-timestamp: 1763740800
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
{ "type": "payment.approved", "data": { "id": "pay_91", "amount": 12000 } }Webhook, Polling, WebSocket, SSE or Queue?
These five things show up together in every conversation about "real time", but they solve different problems.
| Who starts it | Connection | Direction | Typical use | |
|---|---|---|---|---|
| Polling | Whoever wants to know | New one per question | Question and answer | When the provider has no webhook |
| Long polling | Whoever wants to know | Stays open until there's news | Server answers when there's an event | Old chat, environments without WebSocket |
| Webhook | Whoever has the event | One call per event | Server to server | Integration between systems |
| WebSocket | The client opens it | Stays open | Both ways | Chat, games, collaboration |
| SSE | The client opens it | Stays open | Server to browser only | Notifications, progress, streaming AI answers |
| Queue / pub-sub | Producer publishes | Broker in the middle | Producer to consumers | Internal async work |
The differences that confuse people most:
- Webhook vs WebSocket. WebSocket (RFC 6455) is an open connection, usually with a browser, where both sides can talk at any moment. A webhook is a one-off call between two servers. If your front end needs to show the approved payment on screen, the usual path is: the gateway tells your back end via webhook, and your back end tells the browser via SSE or WebSocket.
- Webhook vs SSE. Server-Sent Events, defined in the HTML standard, is the server pushing events to the browser over an open connection, with automatic reconnection. It's what makes an AI chat answer show up word by word.
- Webhook vs queue. A queue is internal infrastructure: you control both sides, and the consumer pulls at its own pace. A webhook crosses company lines. Often the two work together: the webhook arrives and becomes a message in a queue. Stripe even offers to deliver events straight to Amazon EventBridge or Azure Event Grid instead of a webhook.
The Three Truths Every Provider Warns About
1. The Same Event Can Arrive More Than Once
Stripe says your endpoint may receive the same event more than once. Shopify says the same. Asaas documents delivery as "at least once". The reason is always the same: if the provider didn't get your 200 (because the response got lost or took too long), it tries again, even if you already processed it.
The defense is to store the event ID with a unique constraint and ignore anything already seen. That's the subject of the article on idempotency. Each provider sends the ID in a different place: webhook-id in Standard Webhooks, the event id in Stripe and Asaas, X-GitHub-Delivery in GitHub, X-Shopify-Webhook-Id in Shopify.
2. It Can Arrive Out of Order
Stripe states plainly that it doesn't guarantee delivery in the order events were generated. And it asks you not to sort by the created field, because it has one-second resolution and can tie. Asaas offers a sequential mode that keeps the order, at the cost of one failed event holding up all the ones after it.
The safest way out: treat the webhook as a notice that something changed, not as the full truth. When it arrives, fetch the resource from the provider's API and save the state it returns. Stripe recommends exactly this with its "thin" events, which carry only a reference to the object.
3. It May Never Arrive
Every provider retries, but each one has a limit, and they're very different:
| Provider | Time to answer | Retries |
|---|---|---|
| Stripe | Answer 2xx quickly | Up to 3 days, with growing waits; manual resend up to 15 days |
| GitHub | 10 seconds | None automatic; manual redelivery for the last 3 days |
| Shopify | 5 seconds | Up to 8 times in 4 hours; then it removes the subscription |
| Mercado Pago | 22 seconds | Every 15 minutes, with a longer interval after the 3rd |
| Asaas | Answer 200 after saving | After 15 failures in a row, pauses the queue; events stuck for over 14 days are deleted |
GitHub is the one that surprises people most: if your server was down, the events from that window don't come back on their own. And Shopify, after giving up, deletes your subscription, and you have to create it again.
That's why a serious system has a reconciliation plan: every so often, it compares what it received with what the API says, and fetches what's missing.
Receiving the Right Way
Answer Fast and Process Later
If you process everything before answering (update the order, issue the invoice, send the email), you'll blow past the provider's timeout at some peak. It counts that as a failure and sends it again, and now you have a duplicate.
The flow recommended by Stripe, GitHub and Asaas:
- Verify the signature.
- Save the event (a table with a unique ID, or a queue).
- Answer
200. - A worker processes it later.
Verify the Signature Against the Raw Body
Anyone who finds your URL can send a POST saying "payment approved". The signature proves it came from the provider and that nobody touched the content.
The standard is HMAC-SHA256: the provider computes a hash of the body with a secret only you and it know, and sends it in a header. You recompute it and compare.
import express from 'express';
import { Webhook } from 'standardwebhooks';
const wh = new Webhook(process.env.WEBHOOK_SECRET!);
// express.raw: the body arrives as a Buffer, exactly as it was sent
app.post('/webhooks/payments', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = wh.verify(req.body, req.headers as Record<string, string>);
} catch {
return res.status(400).end(); // invalid signature or timestamp outside the tolerance
}
const inserted = await db.query(
`INSERT INTO received_webhooks (id, type, payload)
VALUES ($1, $2, $3) ON CONFLICT (id) DO NOTHING`,
[req.headers['webhook-id'], event.type, event],
);
if (inserted.rowCount === 1) await queue.add('process-webhook', { id: req.headers['webhook-id'] });
res.status(200).end();
});The details that break verification in practice:
- Raw body. If the framework runs
JSON.parsefirst, reserializing changes spacing and order, and the signature doesn't match. Stripe, Shopify and Standard Webhooks require the body exactly as it arrived. - Constant-time comparison. Comparing with
==leaks information through response time. Usecrypto.timingSafeEqualin Node orhmac.compare_digestin Python, as GitHub and Stripe ask. The official libraries already do this. - Timestamp. The timestamp goes into the signature to stop someone from recording a valid request and resending it later (a replay attack). Stripe and the Standard Webhooks library accept up to 5 minutes of difference. Stripe says never to use a zero tolerance (which turns the check off) and to keep the server clock in sync.
- Known scheme only. Stripe tells you to ignore any signature that isn't
v1, so an attacker can't force a weaker scheme. - Framework CSRF. Turn off CSRF protection on the webhook route only, or the framework will reject the POST.
Asaas is the exception: it authenticates with a fixed token in the asaas-access-token header, and forbids using your API key as that token. It's simpler, but a fixed token doesn't guarantee the body wasn't altered, nor does it stop a resend. Combine it with HTTPS, with the event ID and, if you can, with an API lookup before releasing anything valuable.
Sending the Right Way
If your system is the one sending webhooks to customers, the responsibilities flip. The Standard Webhooks spec (version 1.0.0, with official libraries in nine languages) brings the good practices together:
- Three headers:
webhook-id(the same across all attempts, so the customer can deduplicate),webhook-timestampandwebhook-signature. - Signature: HMAC-SHA256 over
id.timestamp.body, in base64, with a secret of 24 to 64 bytes starting withwhsec_. The header accepts several signatures, which lets you rotate the secret without breaking anyone. - Timeout: 15 to 30 seconds per attempt.
- Retries: over several days, with growing waits and a bit of randomness.
- Small payload: under 20 KB, ideally with a reference so the customer fetches the rest from the API.
410 Gone: if the customer answers with this, disable the endpoint.
And a risk that only exists on the sending side: SSRF. The customer registers any URL they want, including http://169.254.169.254/ (the cloud metadata address) or an IP on your internal network. The spec recommends sending requests through a proxy that blocks internal IPs, like smokescreen (open source, from Stripe), and running the workers in a subnet with no access to your services.
If you don't want to build all of this, there are ready-made services: Svix (open source, MIT license) and Hookdeck's Outpost (open source, Apache 2.0).
Testing Locally
The provider needs a public URL, and your localhost isn't one. Options:
- The provider's CLI.
stripe listen --forward-to localhost:4242/webhookreceives Stripe events and forwards them to your machine. - Tunnel. Tools like ngrok expose a local port at a temporary public URL.
- Inspector. webhook.site shows on screen any request that comes in, handy for seeing the real format before writing code.
For automated tests, save real payloads as fixtures and test the three scenarios: invalid signature (400), new event (processed once) and repeated event (not processed again). The back-end testing article shows how.
Myths
- "A webhook is delivered exactly once." No provider promises that. At least once, and the rest is on you.
- "It arrives in order." Only if the provider offers a sequential mode, and at a throughput cost.
- "A webhook replaces the API." It's a notice. For the full, current state, the API is still the source of truth.
- "If it fails, the provider retries forever." GitHub doesn't retry at all; Shopify gives up in 4 hours; Stripe in 3 days.
- "A secret URL is enough." URLs leak in logs, screenshots and history. Without a signature, anyone can forge an event.

Quick check
Frequently Asked Questions
Are webhooks secure?
As secure as the verification you do. With HTTPS, an HMAC signature over the raw body, a timestamp check and deduplication, yes.
Which status code should I return?
Any 2xx means success. Return 200 after saving the event. Use 4xx for an invalid signature, and keep in mind that many providers retry on anything that isn't 2xx.
Can I use the webhook to update the user's screen?
Indirectly. The webhook reaches your back end; from the back end to the browser, use SSE or WebSocket.
Should I follow Standard Webhooks or CloudEvents?
They solve different things. Standard Webhooks defines how to deliver safely (headers, signature, retries). CloudEvents, a graduated CNCF project, defines the event envelope (id, source, type, specversion). You can use both together.
What if the provider has no webhook?
Polling at a reasonable interval, respecting the API's request limits. The rate limiting article explains how not to get blocked.
References
Checked on November 21, 2026:
- Standard Webhooks: specification and website
- Stripe, Webhooks
- GitHub, best practices, redelivery and validation
- Shopify, troubleshooting and duplicates
- Mercado Pago, Webhooks
- Asaas, about webhooks and delivery types
- IETF, RFC 6455: WebSocket and RFC 6202: long polling; WHATWG, Server-sent events
- CloudEvents: specification and CNCF graduation
- Svix, Hookdeck Outpost and smokescreen