Cluster 14 · Edge Runtime · crypto.subtle + Queues

Cloudflare Workers WebCrypto HMAC Verifier & Queue DLQ Architecture

Build zero-Node-polyfill edge webhook gateways on Cloudflare Workers using native `crypto.subtle`, KV/Durable Object replay caches, `RateLimit-*` headers, and Cloudflare Queues DLQs.

100% Browser-Side · WebCrypto crypto.subtle · Strict CSP

3. Exponential Backoff & DLQ Retry Calculator

Jitter + SLA Sizing
Retry & DLQ Policy JSON (webhook-dlq-policy.json)
{
  "schema": "https://webhook.runglab.dev/schemas/sla-retry-policy/v1",
  "deliveryTimeoutMs": 5000,
  "maxAttempts": 11,
  "backoff": {
    "strategy": "exponential",
    "baseDelaySec": 60,
    "multiplier": 3,
    "maxDelaySec": 86400,
    "jitter": "equal"
  },
  "slaTargetHours": 72,
  "expectedTotalSpanSec": 324780,
  "dlq": {
    "enabled": true,
    "retentionDays": 14,
    "replayOnFix": true,
    "alertAfterDlqDepth": 10
  }
}
Expected Time to DLQ
3d 18h 13m
MEETS 72h SLA (3d 18h 13m span)
Daily Retry Load & DLQ Alert
5,500 req/day (Alert >= 10)
11x amplification on failing webhooks
Attempt Wait Band Elapsed Queue / DLQ Action
#1 Immediate 0s (initial) Initial POST delivery (enforce timeout <= 5s)
#2 45s – 1m 15s 1m Exponential retry (preserve original Idempotency-Key)
#3 2m 15s – 3m 45s 4m Exponential retry (preserve original Idempotency-Key)
#4 6m 45s – 11m 15s 13m Exponential retry (preserve original Idempotency-Key)
#5 20m 15s – 33m 45s 40m Exponential retry (preserve original Idempotency-Key)
#6 1h – 1h 41m 2h 1m Exponential retry (preserve original Idempotency-Key)
#7 3h 2m – 5h 3m 6h 4m Exponential retry (preserve original Idempotency-Key)
#8 9h 6m – 15h 11m 18h 13m Exponential retry (preserve original Idempotency-Key)
#9 18h – 1d 6h 1d 18h 13m Capped backoff interval (retry with Idempotency-Key)
#10 18h – 1d 6h 2d 18h 13m Capped backoff interval (retry with Idempotency-Key)
#11 18h – 1d 6h 3d 18h 13m Final retry -> route to Dead-Letter Queue (DLQ) & page/alert on-call
SLA & DLQ Runbook (Markdown)
# Webhook Delivery SLA & DLQ Retry Runbook
- **Attempts**: 11 total deliveries (1 initial + 10 retries)
- **Backoff Curve**: `60s × 3^n` capped at `1d` with `equal` jitter
- **Expected Time to DLQ**: **3d 18h 13m** (Target SLA: 72h — MEETS SLA)
- **Per-Request Timeout**: `5s` (respond 2xx immediately & offload work to queue)
- **Daily Retry Traffic (500 failing events/day)**: 5,500 delivery attempts/day (11x amplification)
- **DLQ Escalation Trigger**: Alert if DLQ depth >= 10 events/day or age > 72h

| Attempt | Wait Interval | Cumulative Elapsed | Behavior |
| :--- | :--- | :--- | :--- |
| #1 | Immediate | 0s (initial) | Initial POST delivery (enforce timeout <= 5s) |
| #2 | 45s – 1m 15s | 1m | Exponential retry (preserve original Idempotency-Key) |
| #3 | 2m 15s – 3m 45s | 4m | Exponential retry (preserve original Idempotency-Key) |
| #4 | 6m 45s – 11m 15s | 13m | Exponential retry (preserve original Idempotency-Key) |
| #5 | 20m 15s – 33m 45s | 40m | Exponential retry (preserve original Idempotency-Key) |
| #6 | 1h – 1h 41m | 2h 1m | Exponential retry (preserve original Idempotency-Key) |
| #7 | 3h 2m – 5h 3m | 6h 4m | Exponential retry (preserve original Idempotency-Key) |
| #8 | 9h 6m – 15h 11m | 18h 13m | Exponential retry (preserve original Idempotency-Key) |
| #9 | 18h – 1d 6h | 1d 18h 13m | Capped backoff interval (retry with Idempotency-Key) |
| #10 | 18h – 1d 6h | 2d 18h 13m | Capped backoff interval (retry with Idempotency-Key) |
| #11 | 18h – 1d 6h | 3d 18h 13m | Final retry -> route to Dead-Letter Queue (DLQ) & page/alert on-call |
WebhookSLA Guard · Live Check $29 WebhookSLA Guard Kit

Verify Live Webhook Replay Defense, 429 Retry-After & DLQ SLA Readiness

Run a live webhook endpoint & SLA audit on WebhookSLA Guard (webhook.runglab.dev), grab the turnkey $29 WebhookSLA Guard Kit (WebCrypto HMAC verifiers, replay-window store, RFC RateLimit-* middleware & DLQ runbooks) on Creem, or audit webhook OpenAPI specs on SpecDiff (spec.runglab.dev). Need a PayPal invoice? Email [email protected].

Webhook SLA, Signature & Retry Specification Matrix

Control / Header Production Baseline Reliability & Security Rationale
Edge Crypto API crypto.subtle.importKey + sign Zero external dependencies; constant-time compare over Uint8Array bytes
Replay Deduplication Durable Object / KV TTL >= tolerance Reject seen `t+v1` or delivery IDs atomically at the edge
Queue + DLQ Cloudflare Queues max_retries + dead_letter_queue Respond HTTP 200 immediately after `env.WEBHOOK_QUEUE.send()`
Cost & Latency < 5ms edge ACK Eliminates provider 5s/10s webhook timeouts under database load spikes

Cloudflare Workers Edge Webhook + Queue Producer (TypeScript)

worker-webhook-ingest.ts
export interface Env {
  STRIPE_WEBHOOK_SECRET: string;
  WEBHOOK_QUEUE: Queue<unknown>;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    if (request.method !== "POST") return new Response("Method Not Allowed", { status: 405 });
    const rawBody = await request.text();
    const sig = request.headers.get("stripe-signature") || "";
    const parts = Object.fromEntries(sig.split(",").map((kv) => kv.split("=")));
    const ts = Number(parts.t || 0);
    const now = Math.floor(Date.now() / 1000);
    if (!ts || now - ts > 300 || ts - now > 30) {
      return new Response("Replay window expired", { status: 400 });
    }
    const enc = new TextEncoder();
    const key = await crypto.subtle.importKey("raw", enc.encode(env.STRIPE_WEBHOOK_SECRET), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
    const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(`${ts}.${rawBody}`)));
    const expected = [...mac].map((b) => b.toString(16).padStart(2, "0")).join("");
    const provided = (parts.v1 || "").toLowerCase();
    if (provided.length !== expected.length) return new Response("Invalid signature", { status: 401 });
    let diff = 0;
    for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ provided.charCodeAt(i);
    if (diff !== 0) return new Response("Invalid signature", { status: 401 });

    await env.WEBHOOK_QUEUE.send({ rawBody, receivedAt: now });
    return new Response(JSON.stringify({ accepted: true }), { status: 200, headers: { "Content-Type": "application/json" } });
  }
};

wrangler.toml Queue + Dead-Letter Queue (DLQ) Config

wrangler-dlq.toml
[[queues.producers]]
queue = "webhook-ingest"
binding = "WEBHOOK_QUEUE"

[[queues.consumers]]
queue = "webhook-ingest"
max_batch_size = 10
max_retries = 8
dead_letter_queue = "webhook-ingest-dlq"

Implementation Steps & Key Insights

  1. Read `await request.text()` once at the Worker entrypoint so exact raw UTF-8 bytes are preserved.
  2. Validate timestamp replay tolerance and `crypto.subtle` HMAC-SHA256 in < 2ms at the Cloudflare edge.
  3. Push the verified envelope onto `WEBHOOK_QUEUE` with `max_retries` + `dead_letter_queue` configured.
  4. Monitor `webhook-ingest-dlq` depth and expose `Retry-After` on any edge rate-limit gates.
  • Cloudflare Workers native `crypto.subtle` runs natively at V8 isolate speed with zero npm dependencies (`stripe` SDK Node polyfills unnecessary on hot path).
  • Decoupling edge signature verification from origin Postgres writes turns 3-second p99 database tail latencies into deterministic 5ms webhook ACKs.
  • Use the Cluster 14 DLQ Schedule Calculator above to size `max_retries` and exponential backoff windows against your enterprise SLA.

Common Production Pitfalls

  • Calling `await request.json()` and re-stringifying before verifying the HMAC signature.
  • Configuring `max_retries` on a Queue without binding a `dead_letter_queue`, silently dropping permanently failing events.
  • Forgetting to check clock skew (`ts - now > 30`) when rejecting replayed timestamps.
Ship Faster: Audit your live endpoint on webhook.runglab.dev or grab the $29 WebhookSLA Guard Kit.

More Enterprise Webhook SLA & Signature Guides

← Back to Webhook SLA Kit Hub · WebhookSLA Guard ($29 Kit) → · SpecDiff OpenAPI Audit → · Cluster 7B: CORS & HMAC → · Cluster 9: OpenAPI OWASP →

Frequently Asked Questions

Does Cloudflare Workers support `crypto.subtle.sign` for HMAC-SHA256 without Node compatibility flags?

Yes — Web Crypto (`crypto.subtle`) is built directly into the standard Workers runtime with zero `nodejs_compat` overhead.

How many retries should I configure on my Cloudflare Queue consumer?

Use Cluster 14's Exponential Backoff & DLQ Calculator above to verify your retry count and delay cap cover your target SLA window (e.g., 24h or 72h).

How does WebhookSLA Guard help Teams running Cloudflare Workers?

Get the turnkey $29 WebhookSLA Guard Kit (edge templates, replay store, `RateLimit-*` middleware & DLQ scripts) at https://webhook.runglab.dev.