What are Webhooks?
Webhooks are HTTP callbacks that one system sends to another when something happens. Instead of polling an API repeatedly, your system receives real-time notifications. For example, when a payment is completed in Stripe, Stripe sends a webhook to your server.
Webhooks vs Polling
| Aspect | Polling | Webhooks |
|---|---|---|
| Latency | High (depends on interval) | Low (real-time) |
| Resource Usage | High (constant requests) | Low (event-driven) |
| Reliability | Always works | Needs retry logic |
Webhook Reliability
- Sign payloads: Use HMAC signatures to verify webhook authenticity.
- Idempotency: Process each webhook at most once using event IDs.
- Retry logic: Implement exponential backoff for failed deliveries.
- Queueing: Use a message queue (Redis, RabbitMQ) to handle webhook spikes.