What is a webhook?
Instead of your app asking "anything new?" every minute, a webhook lets the other service ring your doorbell. Here is what arrives, how to trust it, and what goes wrong.

Key takeaways
- A webhook is an HTTP request a service sends to an address you give it, the moment an event happens.
- Always verify the signature with the shared secret, and never trust the payload otherwise.
- Expect retries and duplicates: record each event ID and process it once, and answer quickly.
Rather than waiting to be asked, a service that supports webhooks sends an automatic HTTP request to an address in your app as soon as something happens on its side: a payment succeeded, a form was submitted, a subscription was canceled. It is an API call in reverse: they call you.
Compare checking your mailbox every ten minutes with having a doorbell. Polling an API is the mailbox trip; a webhook is the courier ringing the bell when the parcel arrives. You do less walking and hear about it right away.
What actually arrives
A webhook is a POST request to a URL you registered, carrying a JSON body that describes the event, plus headers. A payment event looks roughly like `{ "id": "evt_123", "type": "checkout.session.completed", "created": 1795400000, "data": { "object": { "customer_email": "sam@example.com", "amount_total": 1200 } } }`. Your code reads the type, finds the order or user it refers to, updates your database and replies 200 OK. The whole round trip should finish in a few seconds; slow work belongs in a background job.
Trust, retries and duplicates
- 01Verify the signature. Anyone can POST to a public URL. Services sign each webhook with a secret you share with them; your handler recomputes the signature and rejects mismatches. Without this check, someone could fake "payment succeeded".
- 02Handle duplicates. Providers retry when they do not get a quick 2xx, sometimes for days, and may occasionally deliver the same event twice. Store each event ID and skip ones you have already processed (this is called idempotency).
- 03Do not rely on order. "Subscription updated" can arrive before "subscription created". Look up the current state when it matters, instead of trusting arrival order.
- 04Answer fast. Acknowledge, then do slow work later. Timeouts cause retries, which cause duplicates.
Where you will meet webhooks
- Payments: marking an order paid or a membership active (accepting payments).
- Forms and scheduling tools: a new booking or response creates a row in your app.
- Code and deploys: a push to a repository starts a build.
- Messaging: an incoming chat or SMS message hits your bot.
Webhooks when building with Startbase
In a Startbase Cloud project, webhook handlers live in edge functions: server-side TypeScript functions for work that must not run in the browser (edge functions docs). Each function has its own URL, logs and an invoke button for test pings. The signing secret belongs in the project's secrets, never in code (API keys and secrets); for payments, the Stripe webhook secret is saved there as STRIPE_WEBHOOK_SECRET.
Add a Stripe webhook handler as an edge function. Verify the signature with STRIPE_WEBHOOK_SECRET from secrets and reject anything that fails. On checkout.session.completed, mark the matching order paid. Store every processed event ID in a webhook_events table and skip duplicates, reply 200 within a second, and log failures.
Common confusions
- Webhook vs API. With an API, your app asks. With a webhook, the other service tells. Most integrations use both: the webhook says "something changed", an API call fetches details.
- Webhook vs websocket. A websocket is a connection held open for live two-way messages, used for chat and multiplayer. A webhook is one request per event, server to server.
- Testing locally. Providers cannot reach a laptop's localhost; test against a deployed function URL or the provider's test tools.
Frequently asked questions
Is a webhook the same as an API?
It uses the same building blocks (HTTP and JSON) but runs the other way: the provider calls your URL when an event happens, instead of you calling theirs.
How do I make sure a webhook is real?
Check its signature with the signing secret the provider gave you, and reject any request that fails. Many providers also include a timestamp to block replays.
What happens if my webhook handler is down?
Most providers retry with increasing gaps, often for hours or days. Make your handler skip events it already processed so retries are safe.

