Skip to content
Reviewed by Bipeen Sinha Dec 01, 2026

Home › Guides › What Is a Webhook

Tech Explained · 2026

What Is a Webhook? Plain-English Definition, How It Works and Webhook vs API in 2026

A webhook is an HTTP POST that one system sends to a URL you own the moment an event happens, so your code never has to poll an API asking whether anything changed. The sender signs the body, expects a 2xx response quickly, and retries when it does not get one: Stripe keeps retrying for up to 3 days.

1 December 202611 min readBy the 360 Digital Transformation Editorial Team
Key takeaways
  • What is a webhook? It is a reverse API call. Instead of your job asking "anything new yet", the provider POSTs the event to an endpoint you own, usually within a second or two.
  • Webhook vs API is a question about direction. You call an API. A webhook calls you. Nearly every production integration uses both, for different jobs.
  • Verify the signature against the raw bytes. Stripe, GitHub, Shopify and Razorpay all sign with HMAC SHA-256, and parsing the JSON before you check it is the commonest cause of a failed signature.
  • Answer fast, then do the work. GitHub's documentation gives you 10 seconds to return a 2xx. Shopify's gives you 5 seconds for the whole request.
  • Duplicates are the design, not a bug. Razorpay documents at-least-once delivery, so dedupe on the event id before you ship, refund or email anything.
  • Retries are generous, then they stop. Stripe retries for up to three days in live mode; Razorpay disables a webhook that has failed for 24 hours. ngrok's free plan covers 20,000 HTTP requests a month, so practising this costs nothing.

Your payment reconciliation job runs every 15 minutes, and your finance lead still wants to know why an order sat marked unpaid for most of an hour. Nothing is broken. That hour is just what polling costs you, and closing it is the entire reason webhooks exist.

So what is a webhook, in terms your own code has to care about? It is three things you agree to: an HTTPS endpoint you own, a shared secret you store, and a promise that the other side will keep knocking until you answer with a 2xx. Everything difficult about webhooks comes out of that third part.

What Is a Webhook? How the Delivery Chain Actually Works

A delivery has two halves, and they belong to different companies. The provider's half: notice an event, serialise it, sign it, POST it, record whether you answered. Your half: prove the request is genuine, prove you have not already handled it, acknowledge it, and only then do the work. Teams that collapse the last two steps into one are the teams whose webhooks break.

Walk through a concrete one. A customer pays Rs 499 on your store. Razorpay creates a payment.captured event, computes an HMAC SHA-256 hash of the exact JSON body using your webhook secret as the key, puts that hash in the X-Razorpay-Signature header, and POSTs it to the URL you registered. Per Razorpay's documentation, if your server accepts the request but does not respond inside 5 seconds the session is marked a timeout, and a timeout counts as a failure.

One webhook delivery, end to end

The acknowledgement and the work are deliberately separated, because the provider's clock is running.

How a signed webhook is delivered and acknowledged A provider detects an event, signs the raw body with HMAC SHA-256 and POSTs it to your endpoint. Your service verifies the signature, deduplicates on the event id, returns 200 immediately and queues the real work for a background worker. If no 2xx arrives in time, the provider retries with exponential backoff. PROVIDER (Razorpay, Stripe, GitHub) 1. Event occurs payment.captured 2. Sign raw body HMAC SHA-256 + secret 3. POST over HTTPS + unique event id clock starts signed POST YOUR SERVICE 4. Verify signature else 401, no retry 5. Dedupe on id seen before? stop 6. Return 200 now milliseconds, not seconds 7. Queue the job 8. Worker does the work async no 2xx in time: retry with exponential backoff

Timeouts, signature headers and retry windows are taken from the Stripe, GitHub, Shopify and Razorpay webhook documentation, checked 1 December 2026.

Why the provider cares so much about your response code

The status code you return is not a formality. It is the only signal the provider has about whether the event landed, and it decides what happens for the next three days. Return 2xx and the event is done. Return anything else, or nothing at all, and you have joined a retry queue. GitHub's documentation is explicit that a timed out error means no response arrived within 10 seconds of delivery, and that your server should return a 2xx inside that window; the Enterprise Server 3.21 docs give 30 seconds instead, which is worth knowing before you debug the wrong product.

What Is a Webhook vs an API? The Difference That Trips People Up

The phrasing people search for is "webhook vs api", and the comparison is slightly wrong as stated: a webhook is an API, just one where you wrote the server and someone else wrote the client. The useful distinction is direction, and who pays for the latency. If you want the mechanics of the request side first, our guide to what a REST API is covers the same HTTP vocabulary from the other end.

Polling an API

You pay for every question, including the ones with no answer.

Polling: your worker repeatedly asks the provider API for changes Your scheduled worker sends a request every fifteen minutes to the provider API. Most responses report no change, and a change is learned about only at the next scheduled run. Your cron worker Provider API GET, every 15 min mostly "nothing changed"

Worst-case staleness equals your schedule interval. Checked 1 December 2026.

Receiving a webhook

One request, sent only when there is something to say.

Webhook: the provider pushes one signed POST when an event happens The provider sends a single signed POST request to your endpoint at the moment an event occurs, and your endpoint answers with a 2xx status code. Provider Your endpoint signed POST on event 200 OK staleness: about a second

Requires a publicly reachable HTTPS URL. Checked 1 December 2026.

Question Webhook API call you make
Who starts the conversation The provider You
How fresh is the data Roughly a second after the event As fresh as your last poll
Cost of nothing happening Zero requests Every scheduled request still runs
What you must operate A public HTTPS endpoint, always up An outbound client and a schedule
Who handles failure The provider retries you You retry the provider
Authentication direction They prove identity to you, with a signature You prove identity to them, with a key
Ordering guarantee None you should rely on You control the order you ask in
Best at Reacting to events as they happen Asking a precise question, and backfilling history
Bad at Replaying everything that ever happened Low-latency reaction

The practical answer to "which one" is both, doing different jobs. The webhook makes your product feel instant. A nightly job that pulls the provider's own list of payments and compares it against your database is what makes your numbers correct. Teams that run only the webhook discover six weeks later that they are missing eleven events from the afternoon their load balancer was replaced, and nobody noticed because nothing errored.

Here is the honest limitation. Webhooks are a bad source of truth. They are unordered, so a payment.failed can land after the payment.captured that superseded it, and they are not a complete history, so a provider that gives up after 24 hours of failures leaves a silent hole. If you need certainty, the API is the authority and the webhook is just the fast path. Design for that and everything downstream gets simpler.

Webhook Security: Verify the Signature Before You Trust the Body

Your webhook URL is a public endpoint that accepts POST requests from the internet and triggers business actions. That is a sentence worth sitting with. Anyone who learns the URL can send you a convincing payment.captured, and if your handler trusts the JSON you have just given a stranger free products.

Every serious provider solves this the same way: an HMAC of the request body, keyed by a secret only the two of you hold. Stripe's documentation states it generates signatures using HMAC with SHA-256, with a default library tolerance of 5 minutes between the signature timestamp and the current time. GitHub's specifies the X-Hub-Signature-256 header carrying a hex digest prefixed with sha256=, recommended over the legacy SHA-1 header. Razorpay's documents the same scheme in X-Razorpay-Signature, and adds the instruction that matters most: pass the raw request body, and do not parse or cast it first.

That last line is the bug you will write at least once. Frameworks parse JSON for you, and a re-serialised body differs from the original by a space or a key order, which changes the hash completely. Capture the bytes before anything touches them.

import hashlib
import hmac

def verify(raw_body: bytes, header_sig: str, secret: str) -> bool:
    """Compare the provider's HMAC against one we compute ourselves."""
    expected = hmac.new(
        secret.encode("utf-8"),
        raw_body,                  # raw bytes: never json.dumps(parsed_body)
        hashlib.sha256,
    ).hexdigest()
    # constant-time compare, so a wrong guess leaks no timing information
    return hmac.compare_digest(expected, header_sig or "")

Now the receiver itself. Note what it does not do: it does not update an order, send an email, or call another service. It decides whether the request is real, claims the event id, answers, and leaves.

import os
from fastapi import FastAPI, Request, Response
from tasks import claim, enqueue   # your DB write and your queue

app = FastAPI()
SECRET = os.environ["WEBHOOK_SECRET"]

@app.post("/webhooks/payments")
async def receive(request: Request):
    raw = await request.body()     # bytes, before any parsing
    sig = request.headers.get("x-razorpay-signature")
    if not verify(raw, sig, SECRET):
        return Response(status_code=401)     # a forgery: never ask them to retry

    event_id = request.headers.get("x-razorpay-event-id")
    if not event_id:
        return Response(status_code=400)     # malformed: retrying will not help

    if claim(event_id, raw):                 # True only the first time
        enqueue(event_id)                    # the real work runs elsewhere
    return Response(status_code=200)         # acked in milliseconds

Securing the inbound edge of a system is the same discipline whether the caller is a payment gateway or a load balancer, and it is the part of cloud architecture that interview questions keep returning to. 360DT's live AWS Solutions Architect and DevOps program builds exactly this shape in the SAA-C03 module: API Gateway in front, a Lambda that verifies and enqueues, SQS holding the work, and a dead-letter queue catching what fails. If you would rather see the token side of the problem first, our walkthrough of how OAuth 2.0 works covers the outbound half of the same trust question.

Retries, Duplicates and What Idempotency Means Here

Return to the Pune D2C brand. Two engineers run the whole backend, one is on leave, and a deploy at 7pm drops webhook traffic for ninety seconds. What happens to the eleven payments taken in that window depends entirely on numbers published in the provider's documentation, and those numbers differ everywhere.

Four published numbers that decide your design

Read these from the provider you actually use, before you pick a timeout for your own handler.

10 s
GitHub's documented response window on GitHub.com
5 min
Stripe libraries' default signature timestamp tolerance
3 days
Stripe's live-mode automatic retry window
24 hrs
Razorpay failure window before the webhook is disabled

From the Stripe, GitHub and Razorpay webhook documentation, checked 1 December 2026.

Provider Signature header Response window Retry behaviour Deduplicate on
Stripe Stripe-Signature, HMAC SHA-256 with a timestamp Return 2xx quickly; defer complex logic Exponential backoff, up to 3 days in live mode The event id in the payload
GitHub X-Hub-Signature-256, sha256= hex digest 10 seconds on GitHub.com; 30 on Enterprise Server 3.21 Redelivery via the REST API or the UI X-GitHub-Delivery, unchanged on redelivery
Shopify HMAC digest, validated to prove the origin 1 second to connect, 5 seconds for the request Retries, with the count varying by docs version The webhook id header
Razorpay X-Razorpay-Signature, HMAC SHA-256 of the raw body 5 seconds, or the session is marked timeout Exponential backoff for 24 hours, then disabled x-razorpay-event-id, unique per event

Two things follow. Your handler's budget is about one second of real work, because the tightest window in the row you care about is five seconds and you cannot assume a healthy network. And Razorpay's documentation states plainly that it follows at-least-once delivery semantics, telling you to identify duplicates using the x-razorpay-event-id header. Not "might occasionally duplicate". At-least-once. You will receive the same event twice, and the second time must be harmless.

Idempotency is the property that makes a repeated request harmless, and here you get it from the database rather than from cleverness. A unique constraint on the event id, written before anything else happens, turns "have I seen this?" into one atomic question.

CREATE TABLE webhook_events (
  event_id    TEXT PRIMARY KEY,
  payload     JSONB       NOT NULL,
  received_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  status      TEXT        NOT NULL DEFAULT 'pending'
);

-- claim(): returns a row only on the FIRST arrival of this event id.
-- On a duplicate it returns nothing, so enqueue() is never called twice.
INSERT INTO webhook_events (event_id, payload)
VALUES ($1, $2)
ON CONFLICT (event_id) DO NOTHING
RETURNING event_id;

That table doubles as your audit log, which is worth more than it sounds the first time someone asks whether a specific payment notification ever reached you. Absorbing a stream of events without losing or duplicating any of them is core data engineering work, and 360DT's Microsoft Fabric data engineering course covers the same guarantees at pipeline scale, where the stream lands in a lakehouse table instead of a Postgres row.

Testing webhook integration locally, for free

You cannot register localhost as a webhook URL, which is why every integration tutorial reaches for a tunnel. ngrok's published free plan limits allow 3 online endpoints, 20,000 HTTP requests and 1 GB of transfer out per month, at 4,000 requests a minute, with one auto-assigned dev domain you cannot customise. Run ngrok http 8000, paste the HTTPS URL into the provider's dashboard, and you are receiving real events against code on your laptop.

Before that, test with no internet at all. This is the fastest loop there is, and it catches the raw-body mistake immediately.

BODY='{"event":"payment.captured","payload":{"amount":49900}}'
SECRET='whsec_local_test'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" -hex | awk '{print $2}')

curl -i -X POST http://localhost:8000/webhooks/payments \
  -H 'content-type: application/json' \
  -H 'x-razorpay-event-id: evt_local_001' \
  -H "x-razorpay-signature: $SIG" \
  --data-raw "$BODY"

# Now run the exact same command again.
# Correct behaviour: 200 both times, and the worker fires exactly once.

If the second call enqueues a second job, stop and fix that before you write another line. Everything else in webhook handling is recoverable. Charging someone twice is not.

Live course

Build the endpoint that receives the webhook, not just the one that sends it

Live online·Sat–Sun, 8–11 PM IST·12 weeks·Rs 29,999

Prepares you for both AWS Solutions Architect Associate (SAA-C03) and AWS DevOps Engineer Professional (DOP-C02), with hands-on projects covering API Gateway, Lambda, queues and retries. Includes mentor support and placement guidance.

Explore the course
AWS Solutions Architect & DevOps Engineer Course (SAA-C03 + DOP-C02)

Where You Will Meet Webhooks in Real Work

This is not a niche protocol you study and never touch. If you hold any backend, cloud, data or AI engineering job, a webhook is somewhere in your week.

Payments and order state at a small commerce team

The Pune team's whole order pipeline hangs off four Razorpay events. Marking an order paid, releasing it to the warehouse, firing the confirmation message and updating the day's revenue number all start from a POST. When that endpoint is down the business does not stop; it quietly stops knowing things. That is why the queue matters more than the handler.

Deployments triggered by a push

Every CI system you have used is a webhook receiver. GitHub POSTs a push event, the CI service verifies X-Hub-Signature-256, and a pipeline starts. That is why "configure webhook in Jenkins" is such a common search. Our comparison of GitHub Actions against Jenkins walks through both sides of that handshake, and the same plumbing turns up across the cloud and DevOps certification tracks.

Waking an AI agent on an external event

An agent that only runs when a human types at it is a chatbot. An agent that starts because a ticket was created, an invoice arrived or a build failed is an automation, and the thing that wakes it is almost always a webhook feeding a queue. Everything above applies, plus one twist: an agent run costs money and takes minutes, so the dedupe check now protects your token budget as well as your data. That pattern is the spine of 360DT's AI Engineer course on generative AI, RAG and AI agents, and it returns in the CCDV-F developer prep course, where tool handlers face the same at-least-once reality, and in the Generative AI Developer course on the Azure side.

What Usually Goes Wrong Here

Six failures account for most webhook incidents, and a colleague would warn you about them in this order.

1

You parsed before you verified

The framework read the JSON, you re-serialised it to hash it, and now every signature fails. Grab the raw bytes first. Razorpay's docs say this outright and people still miss it.

Raw body only
2

You did the work inside the request

Your handler calls three services and takes six seconds. Shopify's 5-second limit fires, the delivery is marked failed, you get a retry, and the work runs twice.

Ack, then queue
3

You assumed each event arrives once

At-least-once means exactly what it says. Without a unique constraint on the event id, one retry becomes two refunds, and reconciliation finds it a month later.

Idempotency
4

You returned 500 for a payload you will never accept

A malformed body or a bad signature is permanent. Returning 5xx buys you three days of retries for a message you will reject identically every time. Use 400 or 401.

Right status code
5

Something between you and the sender rewrote the body

A proxy that reformats JSON, strips headers or buffers oddly invalidates the HMAC. GitHub's docs warn the payload and headers must reach you unmodified.

Check the hop
6

You logged nothing you can search

When finance asks whether a notification arrived at 3:14pm, "the handler looks fine" is not an answer. Store every event id with its arrival time and status.

Auditability
The pitfall nobody mentions until it bites
  • Events are not ordered. Two events about the same object can arrive out of sequence. Compare a timestamp or a version from the payload before you overwrite state; never trust arrival order.
  • A disabled webhook is silent. Razorpay's documentation says a webhook failing for 24 hours gets disabled. Nothing errors in your code at that point, because nothing is arriving. Alert on absence, not just on failure.
  • The secret belongs in a secret store. A webhook secret committed to a repository is a free pass to trigger your business logic. Rotate it the moment it leaks, and keep accepting the old one while in-flight retries drain.

How to Learn Webhook Integration Properly

You will not learn this from reading. Build one receiver, point a real provider at it, then deliberately break it: return a 500 and watch the retries arrive, replay the same event id twice, change one space in the body and watch the signature fail. An afternoon of that teaches more than a week of documentation, and it costs nothing beyond a free ngrok endpoint.

After that the gap is architectural, not syntactic. Knowing why the queue sits between the endpoint and the worker, how a dead-letter queue stops one poisoned message blocking the rest, and what to put on a dashboard so you notice silence, is what separates a hobby integration from a production one. The AWS Solutions Architect and DevOps course covers that ground live, and a free webinar or a demo class is the cheaper way to judge the teaching first. The next batch of every live course starts in January 2027, Saturday and Sunday, 8:00 to 11:00 PM IST.

If you are starting today, here is what I would actually do, and what I would skip. Write the receiver yourself: verify, claim the event id, enqueue, return 200, in about forty lines. Skip the managed webhook gateway until you are consuming from more than three providers, because before that it adds a vendor and a bill without removing a single one of the six failures above. And do not start with the fanciest provider you can find; start with the one whose documentation publishes its retry schedule, because that number is what you are really designing against. When you want the queue, the dead-letter queue and the alerting built alongside you rather than guessed at, the live AWS course is where that happens.

Frequently asked questions

What is a webhook in simple terms?

A webhook is a message one system sends to a web address you control, the moment something happens on their side. Instead of your software checking repeatedly for news, theirs delivers it. Technically it is an HTTP POST request carrying a small JSON description of the event, plus a signature that proves who sent it.

What is a webhook vs an API?

Direction is the difference. With an API you make the request and wait for an answer, so the data is only as fresh as your last call. With a webhook the provider makes the request to you when the event occurs, so you learn about it in about a second. A webhook is technically an API that you host. Most production systems use both: webhooks for instant reaction, API calls for backfilling and for verifying that nothing was missed.

What is a webhook URL?

It is the HTTPS address you give a provider so it knows where to deliver events, for example https://api.yourshop.in/webhooks/payments. It must be publicly reachable, must accept POST requests, and should be unguessable rather than secret, since security comes from verifying the signature and not from hiding the URL. For local development, a tunnel such as ngrok gives you a temporary public URL that forwards to your laptop.

How do webhooks work behind the scenes?

The provider detects an event, builds a JSON body, computes an HMAC SHA-256 hash of that exact body using your shared secret, and sends both as an HTTP POST to your URL. Your endpoint recomputes the hash to confirm the request is genuine, checks whether it has already seen that event id, returns a 2xx status code straight away, and processes the work in a background job. If no 2xx arrives, the provider retries on a backoff schedule.

How do you test webhooks locally?

Two levels. First, send yourself a POST with curl and a signature you generate with openssl dgst -sha256 -hmac, which tests your verification and dedupe logic with no network involved. Then expose your local server with a tunnel: ngrok's free plan documents 3 online endpoints, 20,000 HTTP requests and 1 GB of transfer a month, and most providers also have a dashboard button to resend a real past event at your tunnel URL.

What is a GitHub webhook used for?

Mostly for triggering automation on repository activity: start a build on push, run checks when a pull request opens, post to a chat channel when an issue is filed, or deploy on a release. GitHub signs deliveries with X-Hub-Signature-256 and, per its documentation, expects a 2xx response within 10 seconds on GitHub.com. Each delivery carries an X-GitHub-Delivery GUID that stays the same if you request a redelivery, which makes it a reliable deduplication key.

What is a webhook endpoint and how is it different from a normal route?

Functionally it is an ordinary POST route, but it has three unusual obligations: it authenticates the caller by signature rather than by session or bearer token, it must respond within a few seconds no matter how much work the event implies, and it must tolerate receiving the same request twice. Those three constraints are why webhook endpoints are usually kept separate from your normal application routes.

Are webhooks secure enough for payment data?

They are, if you do three things: serve the endpoint over HTTPS only, verify the HMAC signature against the raw request body on every single request, and reject anything whose signature timestamp is stale. Stripe's libraries default to a 5-minute tolerance on that timestamp, which limits how long a captured request stays replayable. What is not secure is trusting the body because it looks right, or treating an unguessable URL as authentication.

About this guide. 360 Digital Transformation is an Anthropic Partner and a Microsoft Authorized Training Partner. Other certification bodies, vendors and employers named here are not affiliated with us. Tools and versions change quickly; commands and figures cited were checked on 1 December 2026.

Learn it live with 360 Digital Transformation

Turn this guide into a skill employers can see

Live weekend cohortEMI available

AWS Solutions Architect & DevOps Engineer Course (SAA-C03 + DOP-C02)

Rs. 29,999Rs. 37,499 Save 20%

Tools and platforms you work with

  • Amazon Web Services
  • Terraform
  • Docker
  • Amazon EKS
  • Jenkins
  • GitHub Actions
  • Git
  • Linux
Add bonus modules
See the syllabus and batch dates

Other live courses on this career path