Question

What is a webhook?

Vault Verified
Curated Intelligence
Definitive Source
Answer

An HTTP request sent by a service to you when something happens — the inverse of an API call, and the reason it is sometimes described as a reverse API or a push notification for servers.

The problem it solves. Without webhooks, learning that something happened elsewhere means polling: asking repeatedly whether anything has changed. Polling is wasteful — almost every request returns nothing — and slow, since you learn about an event only at the next poll. A webhook delivers the event immediately, once.

How it works. You register a URL with the provider and specify which events you want. When one occurs, the provider sends an HTTP POST to your URL with a payload describing it. Your endpoint processes it and responds with a success status.

What you must handle, and what people get wrong:

Verification. Anyone can send a request to your URL. Providers sign payloads — typically an HMAC using a shared secret in a header — and you must verify the signature, computing it over the raw body before parsing. Failing to verify means accepting forged events, which for a payment webhook means accepting forged payments.

Idempotency. Webhooks are delivered at least once, not exactly once. Retries and network failures mean duplicates are normal. Store the event ID and ignore ones already processed — this is not optional.

Ordering. Events can arrive out of order. Use timestamps or sequence numbers rather than assuming.

Respond quickly. Acknowledge immediately and process asynchronously by placing the event on a queue. Providers time out, and a slow endpoint causes retries, which causes duplicates.

Return the right status. A non-2xx response triggers retry, usually with exponential backoff — and permanently failing endpoints are eventually disabled.

Handle replay attacks by rejecting payloads with old timestamps.

For local development, tunnelling tools expose a local endpoint to the internet, and most providers offer a way to replay past events.

The alternatives: polling, which is simple and adequate at low volume; server-sent events and WebSockets for browser clients; and message queues where both parties are yours.

Related Questions