Off-by-one error in inventory levels after update from "fetch_stock" webhook

Shopify Partner
7 0 1


We're running into this peculiar problem with inventory levels when using Fulfillment Service with fetch_stock callback.


Our company is acting as a fulfillment service to our (B2B) customers who use Shopify to sell their products.

We manage the stock (inventory) for them, package it and ship it (the whole fulfillment process).


Naturally we use the Shopify Fulfillment Service API to attach our system to their Shopify shop.

The problem is with the discrepancies between the inventory information in both systems (Shopify's and ours).


Let's introduce and example scenario: we have a product P and assume it's stock is exactly 100 items.

This way we can obviously possibly sell 100 items on Shopify, if need be.

Now what happens when a new Order is created in Shopify.


1. Shopify creates the Order, reducing the stock on their side by 1 → the new inventory level for P = 99

2. We get a callback from Shopify with a new Order information.

3. We save it for our side and it goes through multiple steps of processing (e.g. assigning to a warehouse, picking, packing and actually shipping). This can take from a few hours to two days.

4. We immediately reduce the stock on our side (obviously, there's a new order in process) → the new inventory level for P = 99

5. Now Shopify is calling our fetch_stock endpoint every hour. Shopify wants to know the inventory level for the product P. Naturally we send an answer {"P": 99} (as noted above) we already started processing the order.
6. This is where the problem occurs.
Suddenly Shopify realises: before P = 100 but now we got fetch_stock response with P = 99.
    Aha! There's a -1 change for product P.
    So Shopify takes this -1 goes to it's own source of truth (where P is already set at 99)
    and reduces the inventory level to 98.
7. So on our side the inventory level is correct: 99 but in Shopify the inventory is set to 98.
8. This confuses our customers (the shop owners) who usually proceed to manually adjust the inventory.

9. Back to us. We send the shipment out from our warehouse(s).

10. We complete the Fulfillment in Shopify.

11. Shopify wraps up processing of that order (from point 1.) and the stock is actually corrected in the Shop.


So in the end after all the processing on both sides the inventory is equal in both services. Unfortunately in the meantime, due to the "trying to help too much" Shopify presents a faulty inventory level information.



Reply 1 (1)
Shopify Partner
94 7 59

I have this EXACT issue right now. Shopify deducting inventory after an order is placed. Our ERP system also does the same. And every order causes a double deduction.

It's a shame no one from Shopify responded with some pointers on this. I tried contacting Shopify support, and they literally told me they can't support me and I should search around for solutions. Hopfully someone from staff can respond with how we should deal with this behavior from Shopify.