Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Reliable Multi-Tenant
Webhook Delivery Engine.

A production webhook engine pairs a Transactional Outbox + tenant-partitioned queue with per-tenant concurrency bulkheads, per-endpoint circuit breakers, DNS-pinned SSRF egress guards, HMAC-SHA256 replay-resistant signatures, and tiered retry + DLQ replay.
Start the journey5 stages· Last modified Nov 21, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep the architecture evolvable without sacrificing reliability, never share one unbounded worker queue across all webhook tenants—one slow or dead customer endpoint will fill every worker thread and stall healthy tenants unless isolated by per-endpoint circuit breakers and bulkheads.

TL;DR30-second simplified summary
▾

Core Mechanics: Outbound webhooks hit untrusted, unpredictable third-party servers. Sharing one queue causes head-of-line blocking when one customer endpoint stalls at 30s timeouts, while unsanitized URLs invite Server-Side Request Forgery (SSRF).

Visual & Structural Flow: Depicts Domain Event -> Transaction Outbox -> Partitioned Kafka Queue (by tenant_id) -> Per-Tenant Bulkhead Worker Pool (HMAC-SHA256 Signer + Circuit Breaker per endpoint) -> SSRF Egress Guard (Block 169.254/10.x) -> Customer HTTPS Endpoint, with failures routed to Exponential Backoff + Jitter -> DLQ -> Replay.

Trade-Offs & Production: Partitioning by tenant_id preserves per-tenant ordering, while per-endpoint circuit breakers trip after consecutive 5xx/timeouts so dead endpoints move to slow retry queues without blocking healthy tenants.

Failure Modes & Application: Resolve DNS once at egress and validate the target IP is public (blocking 127.0.0.0/8, 10.0.0.0/8, 169.254.169.254) before connecting to stop DNS-rebinding SSRF attacks.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Transactional Outbox Pattern
The Transactional Outbox pattern eliminates dual-write split-brain by inserting domain events into an outbox table inside the exact same ACID database transaction as the business state change, then relaying them asynchronously to Kafka/RabbitMQ.
Bulkhead & Fault Isolation
The bulkhead pattern partitions shared compute, thread pools, connection pools, and memory into isolated compartments so a slow or failing downstream dependency exhausts only its own quota rather than sinking the entire service.
Dead Letter Queues
A secondary quarantine queue that captures messages a consumer repeatedly fails to process after a bounded number of retries, preventing poison pills from blocking healthy traffic.
Full walkthrough · 5 stages
01
STAGE 01 · REQUIREMENTS & MATHL5 · APPLIED DESIGN

Clarify Delivery SLOs, Security & Noisy-Neighbor Bounds.

Why this matters: The problem: size outbound throughput, retry fanout, and security boundaries.

Think of Clarify Delivery SLOs, Security & Noisy-Neighbor Bounds as the intuition layer for Design a Reliable Multi-Tenant Webhook Delivery Engine: The problem: size outbound throughput, retry fanout, and security boundaries.

At 30,000 events/sec (~2 KB payload = ~60 MB/s outbound), healthy endpoints respond in <300 ms, while degraded endpoints stall for 5–10s. The engine must guarantee at-least-once delivery with HMAC-SHA256(timestamp + '.' + payload) headers, strict SSRF blocking, and zero cross-tenant head-of-line blocking.

Component Topology

Clarify Delivery SLOs, Security & Noisy-Neighbor Bounds

ProduceringressPartition LogcomputeConsumerstorageDead-Letter Queuecontrolappend(key)poll(offset)dead-letter
02
STAGE 02 · NAIVE BOTTLENECKSL5 · APPLIED DESIGN

Why Global Worker Pools & Naive URL Fetches Fail.

Why this matters: The failure mode: see how one stalled endpoint exhausts workers and how DNS rebinding bypasses naive URL checks.

Think of Why Global Worker Pools & Naive URL Fetches Fail as the intuition layer for Design a Reliable Multi-Tenant Webhook Delivery Engine: The failure mode: see how one stalled endpoint exhausts workers and how DNS rebinding bypasses naive URL checks.

If 100 global workers pull from one shared queue and Tenant X's webhook hangs for 10s per call, Tenant X quickly occupies all 100 workers—dropping healthy Tenant Y's delivery rate to zero. Separately, validating a hostname with getaddrinfo() and then letting requests.post(url) re-resolve DNS allows DNS rebinding to hit internal 169.254.169.254 cloud metadata IPs.

Request & State Flow

Why Global Worker Pools & Naive URL Fetches Fail

Producer / TXBroker PartitionConsumer GroupDLQ / Retry1. Append event with idempotencykey2. Deliver batch in partitionorder3. Route poison pill after maxretries4. Commit offset after durablesink
Engineering Decision Framework
Problem
How to implement Design a Reliable Multi-Tenant Webhook Delivery Engine without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
To keep the architecture evolvable without sacrificing reliability, never share one unbounded worker queue across all webhook tenants—one slow or dead customer endpoint will fill every worker thread and stall healthy tenants unless isolated by per-endpoint circuit breakers and bulkheads.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Reliable Multi-Tenant Webhook Delivery Engine experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · ENTERPRISE ARCHITECTUREL6 · SCALE & TRADE-OFFS

Outbox -> Tenant Bulkheads -> Circuit Breakers -> SSRF-Pinned Egress.

Why this matters: The mechanism: isolate tenants with bulkheads/circuit breakers and pin validated public IPs.

Capture events via a Transactional Outbox into a tenant_id-partitioned Kafka topic.

Workers enforce per-endpoint concurrency caps (bulkheads) and trip a Circuit Breaker after e.g. 10 consecutive timeouts—routing failing endpoints to delayed retry topics (1m, 5m, 30m, 2h with jitter) and finally a DLQ with manual/API replay.

Webhook Dispatch Pipeline

Isolated Multi-Tenant Webhook Delivery & SSRF Guard

Outbox + KafkaKey by tenant_idBulkhead + CBPer-endpoint capHMAC + SSRF GuardIP-pinned HTTPSRetry / DLQJittered backoff

1.Replay-Safe HMAC: Sign t=<unix_ts>.<body> so receivers reject signatures older than 5m.

2.Circuit Breaker: Trips on dead endpoints so workers never stall on 10s timeouts.

3.DNS-Pinned SSRF: Validates resolved IP is public and connects to that IP directly.

Caption: Combining per-endpoint circuit breakers, DNS-pinned SSRF egress guards, and tiered retry topics keeps healthy tenants fast.

import hmac, hashlib, ipaddress, socket, time

def sign_webhook_payload(secret: str, payload: bytes, timestamp: int | None = None) -> tuple[str, int]:
    """Generate replay-resistant Stripe-style HMAC-SHA256 signature header."""
    ts = int(timestamp or time.time())
    signed = f"{ts}.".encode("utf-8") + payload
    sig = hmac.new(secret.encode("utf-8"), signed, hashlib.sha256).hexdigest()
    return f"t={ts},v1={sig}", ts

def resolve_safe_public_ip(hostname: str) -> str:
    """Resolve hostname once and reject private, loopback, or cloud metadata IPs."""
    ip_str = socket.gethostbyname(hostname)
    ip = ipaddress.ip_address(ip_str)
    if ip.is_private or ip.is_loopback or ip.is_link_local or ip.is_multicast or ip.is_reserved:
        raise ValueError(f"Blocked non-public webhook target IP: {ip_str}")
    return ip_str
04
STAGE 04 · RETRIES & DLQ REPLAYL6 · SCALE & TRADE-OFFS

Tiered Delay Queues, Secret Rotation & Customer DLQ Replay.

Why this matters: Operational control: support zero-downtime secret rotation and safe DLQ replay.

Think of Tiered Delay Queues, Secret Rotation & Customer DLQ Replay as the intuition layer for Design a Reliable Multi-Tenant Webhook Delivery Engine: Operational control: support zero-downtime secret rotation and safe DLQ replay.

Never sleep() inside Kafka consumer threads—publish failed deliveries to dedicated delay topics (retry_1m, retry_15m, retry_2h) with jitter, then park exhausted events in a DLQ for 14 days. During secret rotation, emit dual v1 signatures (old + new secret) for 24 hours so customers deploy zero-downtime key updates.

Lifecycle & Failure Recovery

Tiered Delay Queues, Secret Rotation & Customer DLQ Replay

poll batchsink successpoison / timeoutAppended to LogLeased to ConsumerOffset CommittedMoved to DLQ
05
STAGE 05 · INTERVIEW FOLLOW-UPSL7 · STAFF / PRINCIPAL

Ordering vs. Throughput & Auto-Disabling Dead Endpoints.

Why this matters: Applied problems: balance strict FIFO ordering against head-of-line blocking.

Think of Ordering vs. Throughput & Auto-Disabling Dead Endpoints as the intuition layer for Design a Reliable Multi-Tenant Webhook Delivery Engine: Applied problems: balance strict FIFO ordering against head-of-line blocking.

Default to unordered parallel delivery (most webhooks include created_at and event_id for receiver-side idempotency) and auto-disable endpoints that return 100% 4xx/5xx for 7 consecutive days after emailing the tenant.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why must an SSRF guard resolve DNS once, validate the IP, and connect directly to that IP instead of validating the URL and letting the HTTP library re-resolve DNS?

Recommended Learning Flow