Skip to content

Webhooks explained: what they are, how to receive and send them with signatures, retries, dedup and no SSRF

What a webhook is and how it differs from polling, WebSocket, SSE and queues, the three truths every provider warns about and how to receive and send the way Stripe, GitHub and Shopify document it.

Ramon Gomes 14 min read Level: Intermediate

Also available in: Español, Français, Português

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.

Delivery rider on a motorbike stopped in front of a residential gate, ringing the intercom with a pizza box in hand, at dusk
Nobody calls the pizza place every five minutes. The pizza place rings the intercom when it gets there.

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 POST to 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.

http
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.

Side by side animation: on the left, the system asks the gateway several questions in a row and almost all of them come back empty; on the right, the system waits quietly and gets a single call from the gateway the moment the payment is approved
Polling spends calls asking. A webhook spends one call per event.
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.

Animation of the same event evt_123 arriving twice at the endpoint; the first copy is recorded in a list of already seen IDs and processed; the second finds the ID in the list and is dropped with no effect
The event ID is an idempotency key you get for free.

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.

Animation of two events, invoice paid and subscription created, arriving in swapped order; instead of trusting the arrival order, the system queries the provider's API and saves the correct current state
When in doubt about the order, ask the API for the current state.

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.

Animation of a webhook arriving, being saved to a queue and answered with 200 in under a second, with a 10 second timer far from running out; then a worker picks the event from the queue and does the slow work
The endpoint just stores and confirms. The heavy work goes to the worker.

The flow recommended by Stripe, GitHub and Asaas:

  1. Verify the signature.
  2. Save the event (a table with a unique ID, or a queue).
  3. Answer 200.
  4. 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.

HMAC SHA-256 diagram with a raw body containing value 120, a timestamp and a secret. Two cards compare the computed code with the header: for 120 the codes match and the response is 200; for the changed value 920, the codes differ and the response is 400.
One different character and the signature doesn't match.
ts
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.parse first, 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. Use crypto.timingSafeEqual in Node or hmac.compare_digest in 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-timestamp and webhook-signature.
  • Signature: HMAC-SHA256 over id.timestamp.body, in base64, with a secret of 24 to 64 bytes starting with whsec_. 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.
Animation of a delivery that fails with 500 and is retried with longer and longer waits, 5 seconds, 5 minutes, 30 minutes, 2 hours, until it finally gets a 200
Retrying right away only makes it worse. Waiting longer each time gives the customer time to recover.

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/webhook receives 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.
Cartoon of a mail carrier delivering the same letter for the second time to a person who checks the receipt number in a notebook and hands the letter back with a smile, while another letter flies in through the window out of order
With a numbered receipt in hand, the mail carrier can ring as many times as he likes.

Quick check

1. What's the main difference between a webhook and a WebSocket?
Show answer

Answer: A webhook is a one-off HTTP call between servers; a WebSocket is an open, two-way connection, usually with the browser

They complement each other: the webhook tells the back end, and the WebSocket or SSE tells the screen.

2. Why does signature verification fail when the framework runs JSON.parse first?
Show answer

Answer: Because reserializing the JSON changes bytes in the body, and the signature was computed over the original body

The signature is valid for the exact bytes that were sent.

3. Your server was down for 2 hours. What happens to the GitHub webhooks from that window?
Show answer

Answer: They aren't resent on their own; you can manually redeliver the ones from the last 3 days

That's why reconciliation with the API is part of the design.

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:

Source: https://ramongomessilva.com.br/blog/webhooks-explained · Accessed on December 02, 2026

Share Share on LinkedIn Share on X
Cite this article

Ready-made reference, with today as the access date.

ABNT

Brazilian standard (NBR 6023). Use it in theses and academic papers submitted in Brazil.

GOMES, Ramon. Webhooks explained: what they are, how to receive and send them with signatures, retries, dedup and no SSRF. Ramon Gomes, 28 nov. 2026. Disponível em: https://ramongomessilva.com.br/blog/webhooks-explained. Acesso em: 2 dez. 2026.

APA

American Psychological Association style. Common in scientific papers and journals, especially in the social, behavioral and health sciences.

Gomes, R. (2026, November 28). Webhooks explained: what they are, how to receive and send them with signatures, retries, dedup and no SSRF. Ramon Gomes. https://ramongomessilva.com.br/blog/webhooks-explained

BibTeX

Format for LaTeX users (Overleaf, for example). Paste it into your .bib file or import it into Zotero or Mendeley.

@online{gomes2026webhooksexplained,
  author = {Gomes, Ramon},
  title = {{Webhooks explained: what they are, how to receive and send them with signatures, retries, dedup and no SSRF}},
  organization = {Ramon Gomes},
  year = {2026},
  month = nov,
  date = {2026-11-28},
  url = {https://ramongomessilva.com.br/blog/webhooks-explained},
  urldate = {2026-12-02}
}
Found a mistake?

Wrong fact, broken link, outdated information: tell me and I will fix it.

10 to 2,000 characters. If you can, point to the right source.

Only so I can reply. It never shows on any page of the site.

Written by

Ramon Gomes

Software Engineer

Full stack software engineer. I like taking a messy problem, listening to the people who live with it and shipping something that holds up day to day. These days I split my time between my own products, applied AI and client work.

Available for projects

Need Something Like This Built?

I build websites, systems, apps and AI automations, from design to deploy. Tell me what you need or see what I offer.

Related Articles