What Is a Webhook?
A webhook is an automated mechanism that allows one system to send real-time data to another system when a specific event occurs. It is often referred to as a "reverse API" or "HTTP push notification".
How Webhooks Work
-
1. You provide a callback URL
You provide a destination URL on your receiving server where events should be delivered.
-
2. An event occurs
An event happens on the source platform (such as a subscription renewal, form submission, or repository update).
-
3. HTTP POST request is sent
The source system immediately executes an HTTP POST request carrying event data serialized as JSON or XML.
-
4. Receiver acknowledges receipt
Your receiver confirms receipt with an HTTP 2xx status code and initiates background processing.
Webhooks vs. Traditional Polling
In traditional API polling, your application makes continuous, periodic requests to an API asking "has anything changed?". This consumes bandwidth and computing power when there are no updates.
Webhooks reverse this relationship: the server pushes updates instantly when something happens. This saves bandwidth and reduces latency to near zero.
Security Best Practices
- Verify Signatures: Always verify digital HMAC signatures sent in request headers to guarantee sender authenticity. Check the official documentation for the service you are integrating for current signature verification steps.
- Use HTTPS: Transmit all webhook traffic over TLS encrypted connections.
- Respond Fast: Return a 200 or 204 HTTP status code immediately upon ingestion, delegating heavy business logic to asynchronous background queues.
- Enforce Idempotency: Webhooks may be redelivered due to network timeouts; ensure duplicate deliveries are handled idempotently.
Frequently Asked Questions
- What HTTP method do webhooks usually use?
- Most providers use POST requests with a JSON body, although PUT or GET may occasionally be employed depending on the provider.
- What happens if my server is temporarily offline?
- Most platforms implement exponential backoff retry schedules for failed delivery attempts. Check the documentation of the specific service for retry policies.