Skip to content

Webhooks Complete Guide: Event-Driven Server-to-Server Communication

In this tutorial, you'll learn about webhooks: HTTP callbacks that enable real-time event-driven communication between web applications by sending automated notifications when specific events occur.

Webhooks are user-defined HTTP callbacks that enable real-time push-based communication between web applications, triggered automatically when specific events occur on the provider side.

What You'll Learn

  • Webhook architecture and the push vs polling tradeoff
  • Building webhook providers and consumers
  • Payload signing and signature verification (HMAC-SHA256)
  • Retry policies, idempotency, and dead-letter queues
  • Rate Limiting, monitoring, and security best practices

Why Webhooks Matter

Polling wastes bandwidth and server resources — clients repeatedly check for updates even when nothing changed. Webhooks flip this: the server pushes data the instant an event happens. DodaTech's Durga Antivirus Pro uses webhooks to notify partner SIEM systems about threat detections in real time, eliminating the need for partners to poll a status endpoint while ensuring no threat event is missed.

flowchart LR
    subgraph "Webhook Flow"
        A["Event Occurs\n(threat detected)"] --> B["Webhook Provider\n(Durga Antivirus)"]
        B --> C["Sign Payload\n(HMAC-SHA256)"]
        C --> D["POST to Consumer URL"]
        D --> E["Consumer Endpoint\n(POST /webhook)"]
        E -->|"200 OK"| F["Delivery Success"]
        E -->|"4xx/5xx"| G["Retry Queue\n(exp backoff)"]
        G --> D
        G -->|"Max retries"| H["Dead Letter Queue"]
    end
    style B fill:#dbeafe,stroke:#2563eb
    style E fill:#fef3c7,stroke:#d97706
    style G fill:#fca5a5,stroke:#dc2626
â„šī¸ Info

Prerequisites: HTTP knowledge, JSON familiarity, and basic programming skills in at least one language (JavaScript, Python, or Java).

Webhooks vs Polling

Aspect Webhooks Polling
Direction Server pushes Client pulls
Latency Real-time (ms) Depends on interval (seconds-minutes)
Server load Event-triggered Continuous (even when nothing changes)
Bandwidth Only when events occur Every poll interval
Complexity Higher (retries, signing, scaling) Lower
Best for Time-sensitive notifications Non-critical status checks

Common Mistakes

1. Not Verifying Signatures

Without HMAC signature verification, anyone can send fake webhooks to your endpoint. Always verify signatures using a shared secret.

2. Blocking on Webhook Processing

Webhook senders expect fast responses (2-5 seconds). Queue heavy processing to a background task and return 200 immediately to avoid timeouts.

3. Ignoring Idempotency

Network failures cause duplicate webhook deliveries. Use idempotency keys (event IDs) to detect and safely skip duplicate events.

4. No Retry Logic

Webhooks fail — networks drop, servers restart. Implement exponential backoff with 3-5 retry attempts before moving to a dead-letter queue.

5. Not Returning Proper HTTP Status Codes

Return 200 on success. Return 4xx for bad payloads (no retry) or 5xx for temporary issues (triggers retry). Proper codes prevent unnecessary retries or missed deliveries.

Practice Questions

  1. What is the main advantage of webhooks over polling?
  2. How do you verify a webhook payload is authentic?
  3. What HTTP status code should a webhook consumer return on success?
  4. What is the purpose of a dead-letter queue in webhook delivery?
  5. How do idempotency keys prevent duplicate processing?

Answers:

  1. Webhooks push data in real time when events occur, eliminating the need for clients to poll. This reduces bandwidth, latency, and server load.
  2. The sender signs the payload with HMAC-SHA256 using a shared secret. The receiver computes the expected signature and compares using hmac.compare_digest to prevent timing attacks.
  3. 200 OK. Any 4xx (client error) or 5xx (server error) signals failure and may trigger retries according to the provider's retry policy.
  4. A dead-letter queue stores events that failed after exhausting all retry attempts. It enables manual inspection, replay, and debugging of undeliverable webhooks.
  5. Each event includes a unique idempotency key. The consumer checks if a key was already processed; if so, it skips processing and returns the previous result. This prevents double charges or duplicate actions.

Challenge: Design a webhook system for DodaTech's file scanning service. When a scan completes, notify the user's dashboard (via Websocket) and an external SIEM system (via webhook). Include HMAC signing, retries with exponential backoff, idempotency using scan IDs, and a dead-letter queue for failed deliveries.

FAQ

What is the difference between webhooks and APIs?

APIs follow a request-response pattern — you ask, you receive. Webhooks follow an event-callback pattern — when something happens, the server notifies you. APIs are pull-based; webhooks are push-based.

Can webhooks send binary data?

Yes, webhooks can send any content type, but JSON is most common. For binary data, use base64 encoding within JSON or multipart/form-data.

What happens if my webhook endpoint is down?

The sender retries with exponential backoff (typically 3-5 attempts over 24-72 hours). After exhausting retries, the event is logged as failed or moved to a dead-letter queue.

How do webhooks scale?

Webhooks scale horizontally behind a load balancer. The sender distributes webhooks across registered URLs. Use a message queue (RabbitMQ, Redis) to buffer deliveries during traffic spikes.

Should webhooks be synchronous or asynchronous?

Always process webhooks asynchronously. Return 200 immediately, then process the event in a background queue. Synchronous processing blocks the sender and increases timeout failures.

Try It Yourself

# Test receiving webhooks locally with ngrok
ngrok http 3000

# Forward webhook payloads to your local server
# ngrok gives you a public URL like https://abc123.ngrok.io
# Use that URL in your webhook provider configuration

What's Next

Topic Description
Introduction to Webhooks First steps with webhooks
AsyncAPI Specification Documenting event-driven APIs
WebSocket Guide Bidirectional real-time communication
Server-Sent Events One-way server push
➡ Introduction to Webhooks
➡ AsyncAPI Specification

Published Topics

Monitoring Delivery

✓ Live

Rate Limiting Webhooks Outbound

✓ Live

Rate Limiting Webhooks

✓ Live

Webhook Flow

✓ Live

Webhook Idempotency Keys

✓ Live

Webhook Payload Format

✓ Live

Webhook Project

✓ Live

Webhook Retry Policy

✓ Live

Webhook Security

✓ Live

Webhook Signature Verification

✓ Live

Webhooks Intro

✓ Live

Webhooks Vs Polling

✓ Live

Webhook Ordering Guarantees — Complete Guide

Learn how to manage webhook delivery ordering, understand at-least-once semantics, and implement sequence tracking for reliable event processing.

✓ Live

Building a Webhook Provider — Complete Guide

Learn how to design and implement a webhook provider system that registers consumers, delivers events reliably, and handles retries with exponential backoff.

✓ Live

Being a Webhook Consumer — Complete Guide

Learn how to build a robust webhook consumer that receives, validates, and processes incoming webhook events securely and reliably.

✓ Live

Webhooks with Express.js — Complete Guide

Learn how to build and consume webhooks using Express.js, including signature verification, retry handling, and provider implementation patterns.

✓ Live

Webhooks with Django — Complete Guide

Learn how to build webhook providers and consumers using Django, including CSRF exemption, signal-based event detection, and payload verification.

✓ Live

Webhooks with Spring Boot — Complete Guide

Learn how to build webhook providers and consumers using Spring Boot, including signature verification, retry templates, and asynchronous delivery patterns.

✓ Live

Storing Webhook Events in a Database

Learn how to design a database schema for webhook events, implement storage for audit trails, and build replay and deduplication capabilities.

✓ Live

Webhook Dead Letter Queues — Complete Guide

Learn how to implement dead letter queues for undeliverable webhook events, including storage, monitoring, manual replay, and alerting strategies.

✓ Live

Webhook Filtering — Complete Guide to Selective Delivery

Webhook filtering selectively delivers events based on event type, payload content, or subscriber preferences, reducing unnecessary traffic and simplifying consumer integration.

✓ Live

Webhook Delivery Guarantees — Complete Guide to Reliability

Webhook delivery guarantees define at-least-once, exactly-once, and at-most-once semantics, with retry policies, idempotency keys, and dead-letter queues for reliable event delivery.

✓ Live

Webhook Circuit Breaker — Complete Guide to Preventing Cascading Failures

Webhook circuit breaker pattern protects providers from non-responsive consumers by monitoring delivery failures and temporarily suspending deliveries to unhealthy endpoints.

✓ Live

Webhook Analytics — Complete Guide to Delivery Metrics

Webhook analytics tracks delivery success rates, latency, retry counts, event volumes, and consumer health metrics to monitor and optimize webhook infrastructure performance.

✓ Live

Webhook Schema — Complete Guide to Event Payload Design

Webhook schema defines the structure of event payloads including event types, headers, body format, and versioning to ensure consumers can parse and process webhook data reliably.

✓ Live

Webhook Versioning — Complete Guide to Schema Evolution

Webhook versioning manages changes to event payload schemas over time, ensuring consumers can handle multiple schema versions while migrating to newer formats.

✓ Live

Webhook Testing — Complete Guide to Event Validation

Webhook testing validates that events are correctly formatted, delivered, and processed, using mock servers, contract tests, and delivery simulation tools.

✓ Live

Webhook Batching — Complete Guide to Aggregate Delivery

Webhook batching delivers multiple events in a single HTTP request, reducing connection overhead and improving throughput for high-volume event streams.

✓ Live

Webhook Payload Validation — Complete Guide to Data Quality

Webhook payload validation ensures events meet schema requirements, contain required fields, and have correct data types before delivery to consumers.

✓ Live

Webhook Retry Policy Deep Dive — Complete Guide to Resilience

Webhook retry policy deep dive covers advanced retry strategies including exponential backoff with jitter, circuit breakers, and consumer-specific retry configurations.

✓ Live

Webhook Security Deep Dive — Complete Guide to Protection

Webhook security covers signature verification, IP allowlisting, secret rotation, and payload encryption to prevent forgery and data breaches.

✓ Live

Webhook Consumer Best Practices — Complete Guide to Integration

Webhook consumer best practices cover idempotent processing, validation, error handling, and monitoring for reliable webhook consumption.

✓ Live

Webhook Outbound Rate Limiting — Complete Guide to Throttling

Webhook outbound rate limiting controls how many events are sent to a consumer per time window, preventing overwhelming slow or rate-limited endpoints.

✓ Live

Webhook Database Storage — Complete Guide to Event Persistence

Webhook database storage persists event data for replay, auditing, and analytics using append-only event stores with configurable retention policies.

✓ Live

Webhook batch processing — Complete Guide

Webhook batch processing is a key pattern in event-driven architectures for real-time notifications.

✓ Live

Webhook consumer retry — Complete Guide

Learn Webhook consumer retry. Step-by-step tutorial with practical examples.

✓ Live

Webhook dead letter — Complete Guide

Learn Webhook dead letter. Step-by-step tutorial with practical examples.

✓ Live

Webhook delay strategy — Complete Guide

Learn Webhook delay strategy. Step-by-step tutorial with practical examples.

✓ Live

Webhook event filtering — Complete Guide

Learn Webhook event filtering. Step-by-step tutorial with practical examples.

✓ Live

Webhook idempotency — Complete Guide

Learn Webhook idempotency. Step-by-step tutorial with practical examples.

✓ Live

Webhook multiplexing — Complete Guide

Learn Webhook multiplexing. Step-by-step tutorial with practical examples.

✓ Live

Webhook payload signature — Complete Guide

Webhook payload signature is a key pattern in event-driven architectures for real-time notifications.

✓ Live

Webhook queue persistence — Complete Guide

Webhook queue persistence is a key pattern in event-driven architectures for real-time notifications.

✓ Live

Webhook rate limit consumer — Complete Guide

Webhook rate limit consumer is a key pattern in event-driven architectures for real-time notifications.

✓ Live

All 44 topics in Webhooks Complete Guide: Event-Driven Server-to-Server Communication are published.