Selling across multiple channels (Shopify Plus, Amazon, eBay, TikTok Shop) creates a dangerous operational risk: Inventory Overselling. When a product with only 2 units left sells on Shopify while simultaneously being purchased on TikTok Shop, merchants face cancellations, negative reviews, and marketplace account suspensions. By automating real-time Shopify inventory webhooks with an event-driven worker, inventory levels across all sales channels sync in under 3 seconds.
In this architecture guide, we construct a resilient multi-channel inventory synchronization service in Python, manage SKU mapping tables, handle webhook signature verification with HMAC SHA-256, and implement distributed locks to prevent inventory race conditions.
1. Multi-Channel Synchronization Topology
| Channel Target | API Protocol | Sync Latency Target |
|---|---|---|
| Primary Source: Shopify | Webhook: inventory_levels/update |
Instant event trigger (<800ms) |
| Amazon SP-API | Listings Items API / Feeds API | Sub-2 minutes (Amazon processing queue) |
| TikTok Shop API | Product Fulfillment API (Batch Update) | Sub-3 seconds |
| eBay Trading API | Inventory API (bulkUpdatePriceQuantity) |
Sub-5 seconds |
2. Shopify Webhook Verification & Ingestion (Python)
# shopify_sync_service.py
import hmac
import hashlib
import base64
import os
import httpx
from fastapi import FastAPI, Request, HTTPException, BackgroundTasks
app = FastAPI()
SHOPIFY_WEBHOOK_SECRET = os.environ["SHOPIFY_WEBHOOK_SECRET"]
def verify_shopify_hmac(body: bytes, hmac_header: str) -> bool:
# Verifies that the webhook request originated from Shopify.
digest = hmac.new(
SHOPIFY_WEBHOOK_SECRET.encode("utf-8"),
body,
hashlib.sha256
).digest()
computed_hmac = base64.b64encode(digest).decode()
return hmac.compare_digest(computed_hmac, hmac_header)
async def fan_out_inventory_sync(sku: str, new_quantity: int):
# Pushes new quantity to Amazon, TikTok Shop, and eBay concurrently.
print(f"Propagating SKU: {sku} -> New Stock: {new_quantity}")
async with httpx.AsyncClient() as client:
# Example: Push to TikTok Shop API
# await client.post("https://open-api.tiktokglobalshop.com/api/products/stocks", json=...)
pass
@app.post("/webhooks/shopify/inventory-update")
async def handle_inventory_update(req: Request, background_tasks: BackgroundTasks):
body = await req.body()
hmac_header = req.headers.get("X-Shopify-Hmac-Sha256")
if not hmac_header or not verify_shopify_hmac(body, hmac_header):
raise HTTPException(status_code=401, detail="Invalid HMAC Signature")
data = await req.json()
inventory_item_id = data.get("inventory_item_id")
available_qty = data.get("available")
# Queue background task to update connected channels asynchronously
background_tasks.add_task(fan_out_inventory_sync, str(inventory_item_id), available_qty)
return {"status": "queued"}
Frequently Asked Questions (FAQs)
What happens if a marketplace API is temporarily down?
Never execute marketplace API calls synchronously inside the webhook receiver. Enqueue the sync task onto a Redis-backed queue (such as Celery or BullMQ) with automatic exponential backoff retries to ensure delayed delivery once the marketplace recovers.
Editorial Disclosure: Zelobiz publishes independent engineering benchmarks and architectural evaluations. We may receive affiliate compensation when you subscribe to partner hosting services through our links at no additional cost to you.