Skip to content
SazM Senior dev · Fixed price
EDGE: CMH
ROUTING: 0.1ms
Client Login Get a fix →

Platform Hardening · 8 min read

Resilient Webhook Ingestion: Cryptography & Idempotency

Design resilient webhook architectures with HMAC-SHA256 signature verification, atomic CAS idempotency claims, and zero duplicate billing.

Every major enterprise platform (Stripe, PayPal, GitHub, Twilio) operates under at-least-once delivery semantics. If a network glitch or temporary database lock delays an HTTP 200 response, the provider's retry runner will resend the identical webhook payload minutes or seconds later.

Without robust idempotency guards, duplicate orders are minted, subscription tiers are toggled inconsistently, and customers are charged multiple times.

Cryptographic Verification & Replay Protection

Before parsing webhook bodies, systems must verify the HMAC-SHA256 cryptographic signature and reject requests with timestamp drift exceeding 300 seconds:

export async function verifyWebhookSignature(
  payload: string,
  headerSignature: string,
  secret: string
): Promise<boolean> {
  const encoder = new TextEncoder();
  const key = await crypto.subtle.importKey(
    'raw',
    encoder.encode(secret),
    { name: 'HMAC', hash: 'SHA-256' },
    false,
    ['verify']
  );

  return crypto.subtle.verify('HMAC', key, hexToBuffer(headerSignature), encoder.encode(payload));
}

Atomic Compare-And-Swap (CAS) Deduplication

To prevent race conditions when twin webhooks arrive at separate edge nodes simultaneously, the system claims execution atomically:

INSERT INTO payment_idempotency (idempotency_key, status, locked_until)
VALUES (?, 'processing', datetime('now', '+30 seconds'))
ON CONFLICT(idempotency_key) DO UPDATE SET
  status = CASE WHEN locked_until < datetime('now') THEN 'processing' ELSE status END
RETURNING status;

If the claim fails or the status is already 'settled', the duplicate invocation exits immediately with HTTP 200, protecting business invariants.

Zero Locks Held During Third-Party Network I/O

Processing webhooks often requires notifying customers, firing internal alerts, or executing follow-on accounting entries. SazM decouples these side effects:

// Acknowledge webhook in < 20ms
await claimIdempotencyKey(d1, eventId);
await env.OUTREACH_QUEUE.send({ type: 'payment_settled_notification', eventId });
return Response.json({ received: true });

// SazM ENGINEERING DISPATCH · PRODUCTION REMEDIATION

Senior Engineering Without Agency Overhead

// TRACK A · FIXED-PRICE FIXES (48H SLA)

Single Urgent or Speed Fix

Immediate code-level fixes with zero discovery calls. Emergency root-cause patch within 48 hours for $99, or full Core Web Vitals & speed remediation with before/after audit for $199. 100% money back if the agreed root cause cannot be fixed.

// TRACK B · SENIOR RETAINER & BUILDS

Monthly Plan or Custom Scope

Direct senior-level capacity embedded in your stack. Dedicated monthly engineering ($999/mo, 1 active task at a time, 24–48h PR delivery, pause or cancel anytime), or fixed-scope architectural milestones delivered within a 24h written quote.

✓ 20+ years engineering ✓ 100+ projects in the portfolio ✓ Fixes within 48 hours ✓ 100% money back if not fixed
1 Active Task at a Time
Requests are completed one by one in your priority order. As soon as an active task is shipped, tested, and approved, work starts immediately on your next task within our 24–48h SLA.
48h Emergency SLA
Clock starts as soon as site access details are provided. Delivered with full backup taken first, isolated staging testing, and 100% money back if not fixed.
WordPress Care Plan Scope
Weekly core and plugin updates pre-tested in staging, daily offsite encrypted backups, 24/7 uptime monitoring, and proactive security patching.
Founding Cohort: Pay Nothing Upfront
Zero upfront payment or credit card required. A 20-Year Senior Engineer diagnoses your issue, reproduces it on isolated staging, and deploys the fix. You only pay once you verify the staging reproduction or production fix.