Building Production Software

Webhooks Explained: How They Work and How to Handle Them Reliably

A webhook is how one system tells another that something has happened. They are simple to start with and easy to get subtly wrong. This guide explains them in plain terms and then covers the handling that keeps payments and orders correct.

By Rahul D SarkerPublished November 17, 2026Updated November 17, 20265 min read

Part of our Building Production Software series. Start with Production-Grade Software: Engineering Practices That Prevent Technical Debt.

The Short Answer

What is a webhook?

A webhook is an automated message one application sends to another when an event happens. Instead of your system repeatedly asking “has anything changed?”, the other system sends an HTTP request to a web address you provide, with the details of the event. Payment providers, e-commerce platforms, CRMs and code hosts all use webhooks to notify other systems in real time.

A common description is that a webhook is a reverse API call. With an API, you call them. With a webhook, they call you.

Read the transcript

A customer pays. Your payment provider tells your system. Your server is slow to answer. So the provider tells it again. If you’re not ready for that, you ship the order twice. That message is a webhook. Instead of you asking whether anything has changed, the other system calls you when it does. So how do you handle one without getting it wrong? Here’s how it works. You give them an address. An event happens. They send a request. And your server confirms it. Then four rules keep it correct. Check the signature, because anyone can post to your address. Confirm first, and do the work afterwards. Expect duplicates. And never rely on the order. And keep a safety net. A daily job that compares your records with theirs, and picks up anything missed. Handling an event twice should do no more than handling it once. Build for the retry. The full guide is free at loomstrat.com.

Webhook, API Polling or Streaming

Ways to learn that something changed
Polling an APIWebhookPersistent connection
Who starts itYou ask on a scheduleThey tell you when it happensEither side, over an open connection
DelayUp to the polling intervalSecondsNear instant
Wasted requestsMany; most return nothing newNoneNone
What you must runA scheduled jobA public endpoint that is always availableA long-lived connection and reconnection logic
Best forSystems with no webhooks; periodic reconciliationEvents between serversLive updates to a user’s screen

Webhooks and polling work well together. Use webhooks for speed, and a daily reconciliation job that asks the API for anything you missed.

How a Webhook Works

  1. 1

    You register an address

    In the provider’s settings you enter a URL on your server and choose which events you want, such as “payment succeeded”.

  2. 2

    An event happens

    A customer pays, an order ships, a form is submitted.

  3. 3

    The provider sends a request

    An HTTP POST to your address with a body, usually JSON, describing the event, and a signature in the headers.

  4. 4

    Your server acknowledges

    It replies with a 2xx status code quickly to confirm receipt.

  5. 5

    Your system acts

    It updates the order, sends the email or starts the next step.

  6. 6

    If you did not acknowledge, they retry

    Most providers try again several times over hours or days, with growing gaps.

Stripe’s webhook documentation and GitHub’s are good references for how mature providers do this.

Receiving Webhooks Reliably

The simple version works in a demo. Production needs six things.

Webhook handling rules
RuleWhyHow
Verify the signatureYour endpoint is public; anyone can post to itCompute the signature from the raw body and your secret, compare it with the header, and reject mismatches
Reject old messagesA captured request could be replayedCheck the timestamp in the signed headers and refuse anything older than a few minutes
Acknowledge first, work laterProviders time out after a few seconds and then retrySave the event to a queue or table, return 200, and process it in a background job
Expect duplicatesRetries mean the same event can arrive more than onceRecord each event ID and skip any you have already processed
Do not rely on orderEvents can arrive out of sequenceUse the event’s own timestamp, or fetch the current state from the API before acting
ReconcileSome events will be lost despite retriesA scheduled job that compares your records with the provider’s

The duplicate rule has a name: idempotency. Handling the same event twice must have the same effect as handling it once. Without it, a retried “payment succeeded” event sends two confirmation emails or ships two orders.

Security

  • HTTPS only. Never accept webhooks over an unencrypted connection.
  • Signature on the raw body. Verify before parsing. Many frameworks alter the body when they parse it, which breaks the check.
  • Keep the secret secret. Store it with your other credentials, rotate it if exposed, and use a different one per environment.
  • Trust little. Treat the payload as a hint. For anything involving money, fetch the object from the provider’s API to confirm it.
  • Limit what the endpoint can do. It should accept and queue, nothing more.

Testing and Debugging

  • Local development. Providers’ command-line tools or a tunnelling service forward real webhooks to your machine.
  • Replay. Most dashboards let you resend a past event. Store raw events yourself so that you can replay them too.
  • Logs. Record the event ID, type, time received, result and time processed for every webhook.
  • Alerts. Be told when failures rise or when no events have arrived for an unusual length of time. Silence is the failure that goes unnoticed.

If You Send Webhooks

A SaaS product that offers webhooks to its customers takes on the other side of these rules: sign every message, include an event ID and timestamp, retry with back-off, show delivery logs, let customers replay, and version the payload. The Standard Webhooks specification sets out a common format for signatures and headers, so that customers do not have to learn a new scheme for each provider. Payload changes need the same care as any API change; see our guide to API versioning.

Common Mistakes

  • Doing slow work before replying, which causes timeouts and a storm of retries.
  • No signature check, so anyone who finds the URL can create fake orders.
  • Assuming each event arrives exactly once and in order.
  • Returning an error for event types you do not handle; acknowledge and ignore them.
  • No reconciliation, so a single outage leaves records permanently wrong.

Webhooks are one part of a wider plan for connecting systems, covered in our API integration strategy guide. Building integrations that stay correct under failure is the core of our integrations and APIs work.

Frequently Asked Questions

What is the difference between a webhook and an API?

With an API your system requests data when it wants it. With a webhook the other system sends data to you when an event occurs.

Are webhooks secure?

They are when you use HTTPS, verify the signature on every request, reject old timestamps and confirm important events through the provider’s API.

What happens if my server is down when a webhook is sent?

Most providers retry for hours or days. Add a reconciliation job so that anything missed after retries end is still picked up.

Why did I receive the same webhook twice?

Providers retry when they do not get a quick success response, so duplicates are normal. Store event IDs and ignore repeats.

What status code should a webhook endpoint return?

A 2xx code, usually 200, as soon as the event is safely stored. Return it before doing slow processing.

What is a webhook URL?

The web address on your server that you give to another service so that it can send event notifications to you.

Have a build brief already forming in your head?

Loomstrat Studio scopes, builds, and hands over production software in 3–6 weeks - fixed price, 100% repository ownership.

  • Reply within 24 hours
  • Fixed price before we start
  • Zero technical debt guarantee