Design a Webhook Verification Flow

Medium45 min
1 / 30
System design answer

Design a Webhook Verification Flow

Medium45 min30 sections
understanding•9 min read

Problem Statement: Authenticating Inbound Events Across a Hostile Boundary

Frames webhook verification as an inbound trust-boundary problem: authenticity is a security invariant, event processing is an eventually progressing workflow.

Problem statement

Design a webhook verification flow for a platform that receives high-value events from third-party senders: payment state changes from a PSP, repository events from a code host, order events from commerce platforms, message events from chat tools. Every inbound HTTP POST claims to come from a named sender and asks us to mutate state: settle funds, provision accounts, sync records. Some of those claims are false. The verification flow must decide, within milliseconds and under load, whether a delivery is authentic, fresh, and unseen before any business logic is allowed to act on it.

The core asymmetry is that the sender holds the only proof of authenticity — a shared secret or a private signing key — while the receiver must make a trust decision using nothing but the bytes on the wire. There is no interactive session, no login, no MFA challenge. The entire authentication contract collapses into one signed message: a signature header, a timestamp header, an optional delivery identifier, and the raw request body. If any of those bytes are reordered, recompressed, re-encoded, or partially read before verification, the decision is made on a different message than the one that was signed, and security silently degrades.

Why this problem is distinctive

A normal API authenticates clients with tokens tied to identities. A webhook receiver authenticates messages with signatures tied to sender integrations. Three consequences follow. First, verification must be byte-exact: the receiver must capture the raw body before any middleware parses, trims, or normalizes it, because the signature covers the exact bytes the sender signed. Second, freshness must be enforced separately from authenticity: a perfectly valid signature replayed ten minutes later is still authentic but must be rejected. Third, secrets are long-lived shared state distributed across organizational boundaries, so their lifecycle — provisioning, rotation, grace windows, emergency revocation — is an operational system of its own, with an admin UI and audit trail, not a configuration footnote.

Public operating baseline

This category is standardized in practice. Stripe's documented scheme signs timestamp + "." + raw_body with HMAC-SHA256 per endpoint secret, enforces a default 5-minute tolerance, and retries failed deliveries for up to 3 days with exponential backoff. GitHub signs the raw payload with HMAC-SHA256 (X-Hub-Signature-256), attaches a UUID per delivery (X-GitHub-Delivery) suitable for deduplication and redelivery, and publishes webhook source IP ranges. Slack's documented scheme prefixes a version marker (v0=), signs "v0:" + timestamp + ":" + raw_body, rejects requests older than 5 minutes, and explicitly recommends constant-time comparison. Apple's App Store Server Notifications V2 use an asymmetric scheme: a JWS payload verifiable against Apple's certificate chain, with no shared secret at all. These are the design inputs we translate into a generic multi-sender platform.

The four architectural planes

  1. Ingress plane: TLS termination, raw-body capture, size caps, sender identification, rate limits.
  2. Verification plane: scheme resolution, secret resolution, signature check, timestamp tolerance, replay dedup, verdict emission.
  3. Processing plane: durable enqueue of verified events, idempotent consumers, retries, dead-letter handling.
  4. Governance plane: sender registry, secret lifecycle and KMS-backed storage, rotation admin UI, delivery ledger, alerting, audit.

A strong answer keeps these planes separate. The processing plane may degrade, retry, and lag without weakening verification. The governance plane may rotate secrets without pausing ingestion. And no component in any plane is allowed to mark an event processable before the verification plane has emitted a positive verdict.

Key Highlights

  • •Webhook verification authenticates messages, not sessions: the signature over raw bytes is the entire trust contract.
  • •The raw body must be captured byte-exact before any parsing or normalization, or the signature check validates the wrong message.
  • •Freshness and uniqueness are separate security properties from authenticity and need their own enforcement layers.
  • •The architecture has four planes: ingress, verification, processing, and governance.
  • •Secret lifecycle — rotation, grace windows, revocation — is a first-class subsystem with dual control and audit, not configuration.
Lead With the Trust Boundary
State in the first two minutes that no event reaches business logic before a positive verification verdict. That single sentence separates a security architecture from a generic ingestion pipeline.
Do Not Verify After Parsing
A design that JSON-parses, re-serializes, or trims the body before computing the HMAC verifies a different byte sequence than the sender signed. Byte-exact capture at ingress is mandatory.

Section Rescue Kit

Buzzwords to use:

HMACSigning Base

Safe statements:

  • "I will separate authenticity, freshness, and uniqueness — they are three distinct security properties with three distinct enforcement mechanisms."
  • "Before choosing components, let me define what the receiver is allowed to trust: only bytes covered by a valid, fresh, unseen signature."
Design a Webhook Verification Flow - System Design | WinJob | WinJob