A webhook is a mechanism for real-time notification of events to external systems via HTTP POST requests. Instead of forcing a client to repeatedly poll an API for updates, the source application pushes data immediately when a specific event occurs. This event-driven model eliminates redundant status checks, cuts network overhead, and delivers near-instantaneous synchronization between decoupled services.
How it works
Setting up a webhook requires registering a destination URL—known as a callback endpoint—with the source system and subscribing to specific event types. When an event fires, the provider serializes the event details (typically as a JSON payload) and dispatches an HTTP POST request to that endpoint.
To confirm delivery, the receiving server must parse the request and return a success status code, usually 200 OK or 202 Accepted, within a strict timeout window. If the endpoint returns a 4xx or 5xx error or times out, most webhook providers queue the message and attempt redelivery using a retry policy with exponential backoff.
Because webhook endpoints are exposed to the public internet, providers usually include a cryptographic signature in a custom HTTP header (such as X-Hub-Signature-256). The receiving application computes an HMAC hash using a shared secret key and compares it against the header to verify authenticity before processing the data.
Example
A common DevOps use case is triggering a deployment pipeline whenever code is pushed to a repository. GitHub sends a JSON payload to a build server endpoint, which verifies the signature and runs a deployment script:
POST /hooks/deploy HTTP/1.1
Host: build.example.com
Content-Type: application/json
X-Hub-Signature-256: sha256=8f4b2e...
{
"event": "push",
"ref": "refs/heads/main",
"repository": "api-service",
"commit": "a1b2c3d"
}
Payment gateways like Stripe follow the exact same pattern, sending a charge.succeeded event to an e-commerce backend so the application can fulfill orders without polling the payment API.
What matters when choosing a server or hosting
- Public HTTPS accessibility: Your hosting environment must expose a publicly routable URL over HTTPS with a valid TLS certificate; almost all production providers reject plain HTTP endpoints.
- Low-latency response handling: Providers typically enforce short timeouts (often between 5 and 30 seconds). Your server stack should support asynchronous background workers so the web tier can acknowledge receipt immediately and process heavy tasks later.
- Burst capacity and auto-scaling: Events often arrive in spikes—such as a batch database update or a flash sale. Serverless functions, container autoscalers, or reverse proxies backed by a message queue handle sudden traffic surges without dropping requests.
- Static egress and ingress rules: If you lock down your firewall or WAF, ensure your hosting provider lets you allowlist the sender's IP ranges or inspect custom signature headers without blocking legitimate POST payloads.
Common mistakes
- Running slow tasks synchronously: Performing database migrations, video encoding, or third-party API calls before returning
200 OKcauses timeouts, prompting the sender to mark the delivery as failed and trigger duplicate retries. - Ignoring idempotency: Network hiccups mean webhooks guarantee at-least-once delivery, not exactly-once delivery. Failing to track unique event IDs can result in double-charging customers or duplicate deployments.
- Skipping signature verification: Relying solely on an obscure endpoint URL ("security through obscurity") leaves your system vulnerable to spoofed payloads from unauthorized senders.
- Testing locally without a tunnel: Attempting to register
localhostdirectly with an external provider will fail; developers must use a secure tunneling tool or a staging server during development.
FAQ
What is the difference between a webhook and a standard REST API?
With a standard REST API, the consumer initiates requests to pull data on demand. With a webhook, the provider initiates the HTTP request to push data automatically as soon as an event happens.
What happens if my server is offline when a webhook fires?
Reliable webhook providers temporarily store failed payloads and retry delivery over increasing intervals (exponential backoff). If your server remains unreachable after the maximum retry window expires, the event is typically dropped or logged in a dead-letter queue for manual replay.
Can a webhook use HTTP GET instead of POST?
While technically possible for simple ping notifications, virtually all modern webhooks use POST because it allows structured, arbitrarily large JSON or form-encoded payloads to be transmitted securely in the request body rather than exposed in URL query strings.