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:
- 5-second response timeout: Your webhook endpoint must return an HTTP
200 OK(or2xx) within 5 seconds. Anything slower is treated as a failed delivery, even if your server finishes processing at second 6. - 8 retries over 4 hours: When delivery fails or times out, Shopify retries the webhook 8 times over a 4-hour period.
- Automatic subscription removal: If an endpoint continues failing consistently across all retry attempts, Shopify can automatically remove the webhook subscription—meaning your app stops receiving
orders/createorproducts/updateevents entirely until re-registered.
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:
- Flash-sale bursts: When a store runs a drop, hundreds of
orders/createandinventory_levels/updateevents fire simultaneously, saturating database connection pools. - 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.
- 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:
- Ingestion route (must finish under ~500 ms):
- Read the raw request body bytes.
- Verify
X-Shopify-Hmac-Sha256against 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.
- 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:
- Deduplicate on
X-Shopify-Webhook-Id: Store each processed webhook ID in a unique database column or short-lived cache before running side effects. - Compare resource timestamps: When updating order or inventory state, check the payload’s
updated_attimestamp against your stored record so older retried events never overwrite newer state.
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:
- Spin up a 24h capture URL: Visit EdgeHook to generate an unauthenticated
/in/:idsandbox URL on Cloudflare Workers. - Inspect the Shopify event: Trigger a Shopify webhook (via Shopify Admin test notifications or Shopify CLI) to your
/in/:idURL. EdgeHook stores payloads up to 256 KB (keeping the newest 200 events for 24 hours) and lets you inspectX-Shopify-Topic,X-Shopify-Shop-Domain,X-Shopify-Webhook-Id, and the raw JSON body. - 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:
- Live today (Day 1): Instant 24-hour unauthenticated webhook sandbox (
/in/:idcapture and/api/sandbox/:id/eventsinspection), the zero-dependencyedgehook-cli(listen,replay,pull,send), the waitlist, and Founding Member pre-order checkout via Polar when configured. - On the roadmap (not yet live): A multi-tenant hosted edge proxy that accepts Shopify webhooks at the Cloudflare edge within milliseconds, verifies
X-Shopify-Hmac-Sha256before forwarding, runs automatic exponential retries when your origin slows down past 5 seconds, supports 1-click hosted replay from the dashboard, sends Slack/Discord failure alerts, and includes 14-day (Indie, $29/mo) and 30-day (Pro, $49/mo) retention tiers.
Next Steps
- Inspect a Shopify webhook in 10 seconds: Grab a live 24h sandbox URL at EdgeHook.
- Need an edge buffer in front of your Shopify app? Join the waitlist at /#waitlist to help shape the hosted retry proxy.
- Check out
edgehook-cli: Browse the source and docs at /.
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.