← All Guides Updated 2026-12-01

Handling Shopify's 5-Second Webhook Timeout with a Retry Queue

How Shopify's 5-second webhook timeout and 8-retry / 4-hour delivery policy work, plus how to acknowledge fast, verify HMAC-SHA256 signatures, and replay missed payloads.

If you build Shopify apps or custom storefronts, Shopify webhooks are far less forgiving than most developers expect. A single slow inventory sync or cold database connection can breach Shopify’s timeout, drop orders out of sync, and eventually get your webhook subscription deleted automatically.

Understanding Shopify’s exact delivery SLA—and decoupling ingestion from processing—prevents silent data loss.

Shopify’s Webhook SLA: 5 Seconds and 8 Retries Over 4 Hours

Unlike payment processors that retry for days, Shopify enforces a strict delivery window:

Because 5 seconds includes DNS, TLS handshake, serverless cold start, HMAC verification, and your database writes, doing real business logic inline inside a Shopify webhook handler is risky.

Why Shopify Handlers Breach the 5-Second Window

Even fast code hits 5 seconds under real store traffic:

  1. Flash-sale bursts: When a store runs a drop, hundreds of orders/create and inventory_levels/update events fire simultaneously, saturating database connection pools.
  2. Chained Shopify Admin API calls: Fetching line-item metafields or customer tags from the Shopify GraphQL/REST API inside the webhook handler frequently adds 1–3 seconds per request.
  3. Serverless cold starts: Cold starts on Node.js serverless runtimes can consume 1–2 seconds before your verification logic even executes.

The Architecture Fix: Verify, Enqueue, and Return 200 OK

The reliable pattern for Shopify webhooks splits ingestion into two phases:

  1. Ingestion route (must finish under ~500 ms):
    • Read the raw request body bytes.
    • Verify X-Shopify-Hmac-Sha256 against your Shopify app secret.
    • Deduplicate using X-Shopify-Webhook-Id (Shopify can deliver duplicates).
    • Persist the raw payload to a queue or outbox table, then immediately return 200 OK.
  2. Background worker:
    • Pulls queued jobs, calls the Shopify Admin API, updates ERP/inventory state, and applies its own exponential backoff if downstream services fail.

Here is a clean TypeScript implementation using Node’s built-in node:crypto module:

import crypto from "node:crypto";

interface IncomingWebhook {
  rawBody: string;
  hmacHeader: string | null;
  webhookId: string | null;
  topic: string | null;
  shopDomain: string | null;
}

export function verifyShopifyHmac(
  rawBody: string,
  hmacHeader: string,
  appSecret: string
): boolean {
  const computed = crypto
    .createHmac("sha256", appSecret)
    .update(rawBody, "utf8")
    .digest("base64");

  const expectedBuf = Buffer.from(computed, "utf8");
  const actualBuf = Buffer.from(hmacHeader, "utf8");

  if (expectedBuf.length !== actualBuf.length) {
    return false;
  }

  return crypto.timingSafeEqual(expectedBuf, actualBuf);
}

export async function handleShopifyWebhook(
  req: IncomingWebhook,
  appSecret: string,
  enqueueJob: (job: {
    webhookId: string;
    topic: string;
    shopDomain: string;
    payload: string;
  }) => Promise<void>
): Promise<{ status: number; body: string }> {
  if (!req.hmacHeader || !req.webhookId || !req.topic || !req.shopDomain) {
    return { status: 400, body: "Missing required Shopify webhook headers" };
  }

  const valid = verifyShopifyHmac(req.rawBody, req.hmacHeader, appSecret);
  if (!valid) {
    return { status: 401, body: "Invalid X-Shopify-Hmac-Sha256" };
  }

  // Enqueue into a fast durable store (D1, Redis, SQS, Postgres outbox)
  // keyed by req.webhookId to ensure idempotency.
  await enqueueJob({
    webhookId: req.webhookId,
    topic: req.topic,
    shopDomain: req.shopDomain,
    payload: req.rawBody,
  });

  // Acknowledge well inside Shopify's 5-second timeout
  return { status: 200, body: "OK" };
}

Always hash the exact raw UTF-8 body—never JSON.stringify(parsedBody). Any re-serialization changes key ordering or whitespace and invalidates X-Shopify-Hmac-Sha256.

Handling Idempotency and Out-of-Order Events

Even when your endpoint responds within 5 seconds, distributed systems still deliver duplicate or out-of-order events. An orders/updated webhook can occasionally arrive right after orders/cancelled, or a network blip right after your server sends 200 OK can cause Shopify to retry the same X-Shopify-Webhook-Id.

Two small safeguards eliminate most downstream corruption:

Capturing and Replaying Shopify Payloads Locally with EdgeHook

Shopify order and fulfillment payloads are large and nested, and triggering real test checkouts for every bug fix slows down development. Using EdgeHook’s Day-1 live tools, you can capture real Shopify events once and replay them locally as many times as needed:

  1. Spin up a 24h capture URL: Visit EdgeHook to generate an unauthenticated /in/:id sandbox URL on Cloudflare Workers.
  2. Inspect the Shopify event: Trigger a Shopify webhook (via Shopify Admin test notifications or Shopify CLI) to your /in/:id URL. EdgeHook stores payloads up to 256 KB (keeping the newest 200 events for 24 hours) and lets you inspect X-Shopify-Topic, X-Shopify-Shop-Domain, X-Shopify-Webhook-Id, and the raw JSON body.
  3. Pull and replay locally with edgehook-cli:
# Download captured Shopify events from your 24h sandbox
npx edgehook-cli pull <sandbox-url-or-id> --save ./.edgehook/shopify

# Replay saved events to your local handler with a 250ms delay between requests
npx edgehook-cli replay ./.edgehook/shopify --to http://localhost:3000/api/webhooks/shopify --delay 250

Because edgehook-cli preserves the original headers and body (stripping only hop-by-hop headers like host and content-length), your local handler still sees the exact X-Shopify-Hmac-Sha256 header and raw body bytes—making signature verification tests completely faithful.

You can also capture directly on localhost with edgehook listen:

npx edgehook-cli listen --port 4000 --forward http://localhost:3000/api/webhooks/shopify --save ./.edgehook/shopify

Live Today vs. On the Roadmap

Here is the honest breakdown of what EdgeHook does today versus what we are building next:

Next Steps

Debug your webhooks in seconds

Inspect real Stripe, Shopify, or Clerk payloads in our free 24-hour Cloudflare Workers sandbox (live today), or join the waitlist for managed retries and replay.

Open Live Sandbox Join Waitlist