惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

M
MIT News - Artificial intelligence
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
G
Google Developers Blog
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
月光博客
月光博客
B
Blog
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
博客园_首页
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
Jina AI
Jina AI
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Async Architectures for Shopify Operations: Patterns That...
Asad Abdulla · 2026-05-13 · via DEV Community

Asad Abdullah Zafar

Shopify's webhook delivery timeout is 5 seconds. After 19 consecutive failures, Shopify removes the subscription entirely. Your app silently stops working for every affected merchant.
Synchronous webhook handlers cause this. Async architecture prevents it.
Here are the five patterns every Shopify developer needs in production.

  1. The 50ms Rule: What Belongs in the Webhook Handler Everything in your webhook handler that isn't HMAC validation and queue enqueue is a liability.
js// ✅ Async webhook handler — returns 200 in under 50ms
app.post('/webhooks', express.raw({ type: '*/*' }), async (req, res) => {
  const hmac    = req.headers['x-shopify-hmac-sha256'];
  const topic   = req.headers['x-shopify-topic'];
  const shop    = req.headers['x-shopify-shop-domain'];
  const webhook = req.headers['x-shopify-webhook-id'];

  if (!verifyShopifyHmac(req.body, hmac)) {
    return res.status(401).send('Unauthorized');
  }

  await ingestionQueue.add('webhook', {
    topic, shop, webhookId: webhook,
    payload: JSON.parse(req.body)
  });

  res.status(200).send('OK'); // Return before any processing
});

Enter fullscreen mode Exit fullscreen mode

Everything else — database writes, API calls, notifications — goes into a background worker.

  1. Three-Tier Queue Topology One queue for everything means a slow fulfillment API backs up your ingestion layer. Separate by concern:
js// Tier 1: Ingestion — validate and route only
const ingestionQueue = new Queue('shopify:ingestion', { connection });

// Tier 2: Domain queues — isolated scaling + retry policies
const ordersQueue      = new Queue('shopify:orders',      { connection });
const inventoryQueue   = new Queue('shopify:inventory',   { connection });
const fulfillmentQueue = new Queue('shopify:fulfillment', { connection });

// Tier 3: Notifications — lower priority, higher tolerance
const notificationQueue = new Queue('shopify:notifications', { connection });

Enter fullscreen mode Exit fullscreen mode

Each domain queue gets its own retry policy. Order processing: 5 retries, 2-minute exponential backoff. Notifications: 3 retries, 30-second delay. Mixing them forces a single policy compromise on everything.

  1. Saga Pattern for Multi-Step Fulfillment Any workflow spanning more than one external API call needs compensating transactions. Without them, a mid-workflow failure leaves your system partially applied with no automatic recovery path.
js// Step 1: Reserve inventory → emit inventory.reserved or inventory.insufficient
eventBus.subscribe('inventory-service', 'w1', async (event) => {
  if (event.type !== 'order.confirmed') return;
  try {
    await reserveInventory(event.shop, event.payload.lineItems);
    await eventBus.emit('inventory.reserved', event.shop, event.payload);
  } catch (err) {
    await releasePartialReservations(event.shop, event.payload.orderId);
    await eventBus.emit('inventory.insufficient', event.shop, event.payload);
  }
});

// Step 2: Submit to 3PL → trigger only after inventory confirmed
eventBus.subscribe('fulfillment-service', 'w1', async (event) => {
  if (event.type !== 'inventory.reserved') return;
  try {
    const id = await submit3PLOrder(event.payload);
    await eventBus.emit('fulfillment.submitted', event.shop, { ...event.payload, id });
  } catch (err) {
    await releaseReservation(event.shop, event.payload.orderId); // Compensate
    await eventBus.emit('fulfillment.failed', event.shop, event.payload);
  }
});

Enter fullscreen mode Exit fullscreen mode

Each step is an independent async worker. A 3PL outage pauses fulfillment without touching inventory reservation or order status updates for orders already past that step.

  1. Idempotency Keys: The Minimum Viable Duplicate Guard Shopify guarantees at-least-once delivery. Your workers will execute the same payload more than once.
jsasync function processOrder(shop, orderId, payload) {
  const key   = `processed:order:${shop}:${orderId}`;
  const isNew = await redis.set(key, '1', { NX: true, EX: 86400 });

  if (!isNew) return { status: 'duplicate' }; // Already done

  try {
    await updateCRM(shop, payload.customer);
    await submitFulfillment(shop, payload);
    await sendConfirmation(shop, payload.email);
    return { status: 'processed' };
  } catch (err) {
    await redis.del(key); // Allow retry
    throw err;
  }
}

Enter fullscreen mode Exit fullscreen mode

SET NX is atomic. Two workers racing on the same key cannot both proceed. Deleting the key on failure ensures retries work correctly.

  1. Sharded Scheduled Jobs — Prevent the Thundering Herd A nightly reconciliation firing for 10,000 shops simultaneously at 2am UTC saturates your database and API rate limits in seconds.
js// Hash shop ID into time-staggered buckets
function getScheduleMinute(shopId) {
  return Number(BigInt(shopId) % BigInt(60)); // 0–59 minutes past the hour
}

// Shop A fires at 2:00am, Shop B at 2:03am, Shop C at 2:47am...
await schedulerQueue.add(
  `reconcile:${shop}`,
  { type: 'reconcile', shop },
  { repeat: { pattern: `0 ${getScheduleMinute(shopId)} 2 * *` } }
);

Enter fullscreen mode Exit fullscreen mode

Distributes 10,000 jobs across a 60-minute window. No thundering herd. No database connection pool saturation at 2:00:00.

The Async Pattern Reference










































Pattern Trigger Shopify Use Case Key Concern
Job Queue Webhook / API event Order sync, inventory update Retry + DLQ
Event Bus Domain event CRM, ERP, analytics fan-out Consumer isolation
Saga Multi-step transaction Order fulfillment workflow Compensating transactions
Scheduled Jobs Time-based Billing, reports, reconciliation Thundering herd prevention
Deferred Loading Page request Hydrogen reviews, inventory Streaming non-critical data

Full guide with Redis Streams consumer group implementation, BullMQ three-tier topology, and Hydrogen defer() patterns: https://kolachitech.com/async-shopify-architecture