Muhammad Masad AshrafLearn how to design a distributed Shopify inventory sync system using microservices, event queues, and fault-tolerant patterns that keep stock counts accurate across every channel.
Keeping inventory accurate across Shopify, warehouses, and marketplaces sounds simple. At scale, it is one of the hardest engineering problems in ecommerce.
A single API call after each sale works fine at 200 orders a day. At 20,000 concurrent transactions, it collapses.
Here is what breaks first:
These are predictable failure modes of monolithic sync. A distributed architecture fixes all of them.
1. Event Producer Layer
Captures inventory change events from Shopify webhooks, WMS, POS, and marketplaces.
2. Message Queue Layer
Events land in a durable queue (Kafka, RabbitMQ, SQS). Nothing gets lost.
3. Microservices Processing Layer
Dedicated services consume events, apply business logic, push updates downstream.
4. State Store Layer
Redis holds the current inventory truth. Shopify is updated from here asynchronously.
Each layer scales independently. Each can fail without taking down the others.
Stop polling. React to events.
Shopify fires these webhooks you need to capture:
inventory_levels/updateorders/createorders/cancelledrefunds/createEach webhook hits your receiver, gets acknowledged immediately, then lands on a queue for async processing.
Never process a webhook synchronously inside the HTTP response window. Timeouts will cause missed events and your inventory will drift.
| Service | Job |
|---|---|
| Webhook Receiver | Validates HMAC, publishes to queue |
| Order Event Consumer | Reads order events, calculates deltas |
| Inventory Adjuster | Applies changes with optimistic locking |
| Shopify Sync Service | Pushes updates via GraphQL API |
| WMS Connector | Bidirectional warehouse sync |
| Notification Service | Low-stock alerts and reorder triggers |
One service, one job. Deploy and scale them independently.
Two orders. One unit left. Both read stock as 1. Both decrement. Stock hits -1.
Here is how you stop it:
Optimistic Locking
Version numbers on every record. Assert version has not changed before writing. Retry on conflict. Best for low-contention SKUs.
Pessimistic Locking
Lock before reading. One writer at a time. Slower but safe. Use during flash sales.
Atomic Counters (Recommended)
Redis DECRBY is atomic. Use Redis as your inventory counter, sync to Shopify asynchronously. Fastest and most reliable for high volume.
If you skip any of these, you will debug silent inventory drift at 2am.
Do not hit the Shopify API on every inventory read.
Use write-through caching with Redis:
TTL of 30 to 60 seconds works for most inventory read patterns.
| Queue | Best For |
|---|---|
| AWS SQS | Simplest to operate, great for most stores |
| Apache Kafka | High volume, ordered event streams |
| RabbitMQ | Complex routing between services |
SQS is the right default. Move to Kafka only when you need strict event ordering at millions of events per day.
Set alerts on DLQ growth and queue lag. These are your earliest warning signals before inventory starts drifting.
A distributed Shopify inventory sync system rests on four things:
Get these right and oversells, stale counts, and silent sync failures become engineering history rather than daily incidents.
Originally published on KolachiTech