DEV Community

Cover image for Real-time Shopify Inventory Sync with Firebase for Multi-Location Stores
Lucy
Lucy

Posted on

Real-time Shopify Inventory Sync with Firebase for Multi-Location Stores

Managing inventory across multiple Shopify locations is one of the biggest operational challenges for fast-growing ecommerce brands. Stockouts, overselling, inaccurate store counts, and delayed updates are common when products move quickly between warehouses, pop-ups, retail stores, and online orders.

To address this, many teams adopt a real-time architecture using Firebase, enabling instant syncing of Shopify inventory data across dashboards, mobile apps, and backend systems.

As brands scale, they often rely on Expert Shopify Developers to implement this kind of infrastructure because Shopify's native inventory APIs are powerful but require external systems to enable real-time updates.

In this blog, you’ll learn exactly how to build a Shopify + Firebase Realtime Inventory Sync system using Shopify Webhooks, Firebase Cloud Functions, Firestore/Realtime DB, and Admin API. We'll walk through both the architecture and the coding implementation.

Why use Firebase for Inventory Sync

Firebase is ideal for multi-location inventory workflow because:
1. Realtime Updates:
Any change to Shopify Inventory is instantly reflected in Forestone or the real-time Database.
2. Perfect for Multi-Location
Each location can maintain its own node or location
3. Effortless Scaling
Even if your app grows to millions of reads, Firebase auto-scales without DevOps.
4. Instant Communication Across Teams
Retail staff, warehouse teams, and apps can subscribe to realtime inventory updates.
5. Works Smoothly with Shopify Webhooks
Shopify pushes inventory updates → Firebase stores them instantly → your systems react in milliseconds.

High-Level Architecture

Shopify Store
    ↓ (Inventory Update Webhook)
Cloudflare/AWS/Node Server OR Firebase Cloud Function
    ↓
Firebase Firestore / Realtime DB
    ↓
Internal dashboards, apps, POS, or multi-warehouse systems
Enter fullscreen mode Exit fullscreen mode

What Triggers the Sync

  • Orders being placed
  • Inventory adjustments
  • Fulfillments
  • Returns
  • Restocks
  • Location-level stock movements

Every time one of these events occurs, Shopify fires a webhook.

Step 1: Configure Shopify inventory Webhooks

You can create webhooks for:

`- inventory_levels/update

  • inventory_items/update
  • products/update`

Example request to create the webhook:

POST /admin/api/2024-01/webhooks.json
{
  "webhook": {
    "topic": "inventory_levels/update",
    "address": "https://your-domain.com/webhooks/inventory",
    "format": "json"
  }
}

Enter fullscreen mode Exit fullscreen mode

Once these webhooks are active, Shopify notifies your backend whenever inventory changes.

Step 2: Build a Firebase Cloud Function to process Webhooks

Youc can Firebase Cloud Functions as your servless endpoint for receiving Shopify Webhooks
Install dependencies:

npm install firebase-admin firebase-functions crypto

Enter fullscreen mode Exit fullscreen mode

Initialize Firebase in your function:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const crypto = require("crypto");

admin.initializeApp();
const db = admin.firestore();

Enter fullscreen mode Exit fullscreen mode

Step 3: Validate Shopify Webhook HMAC

Shopify signs every webhook. Validate it before processing:

function isValidShopifyWebhook(req) {
    const hmacHeader = req.get("X-Shopify-Hmac-Sha256");
    const body = JSON.stringify(req.rawBody);

    const hash = crypto
        .createHmac("sha256", process.env.SHOPIFY_SECRET)
        .update(body, "utf8")
        .digest("base64");

    return hash === hmacHeader;
}


Enter fullscreen mode Exit fullscreen mode

Step 4: Write the Firebase Cloud Function to Sync Inventory

exports.syncInventory = functions.https.onRequest(async (req, res) => {
    if (!isValidShopifyWebhook(req)) {
        return res.status(401).send("Invalid signature");
    }

    const data = req.body;

    const inventoryItemId = data.inventory_item_id;
    const locationId = data.location_id;
    const available = data.available;

    try {
        await db
            .collection("inventory")
            .doc(inventoryItemId.toString())
            .collection("locations")
            .doc(locationId.toString())
            .set({
                quantity: available,
                updatedAt: admin.firestore.FieldValue.serverTimestamp()
            });

        return res.status(200).send("Inventory synced");
    } catch (err) {
        console.error(err);
        return res.status(500).send("Error syncing inventory");
    }
});

Enter fullscreen mode Exit fullscreen mode

What this Function Does

  • Validates the webhook
  • Extracts inventory item ID, location ID, and quantity
  • Stores it in Firestore in a structured hierarchy
  • Timestamp ensures version tracking With this, every update in Shopify becomes instantly viewable across your Firebase-powered dashboards.

Step 5: Real-time UI Listeners (For Admin Dashboards or Warehouse Apps)

db.collection("inventory")
  .doc(productId)
  .collection("locations")
  .onSnapshot(snapshot => {
      snapshot.docs.forEach(doc => {
          console.log("Updated location:", doc.id, doc.data());
      });
  });
Enter fullscreen mode Exit fullscreen mode

Step 6: Writing Inventory Back to Shopify (Optional)
If you want Firebase to push changes back to Shopify—for example, if a warehouse updates stock manually—use Shopify Admin API:

const axios = require("axios");

async function updateShopifyInventory(inventoryItemId, locationId, qty, shop, token) {
    await axios.post(
        `https://${shop}/admin/api/2024-01/inventory_levels/set.json`,
        {
            inventory_item_id: inventoryItemId,
            location_id: locationId,
            available: qty
        },
        {
            headers: {
                "X-Shopify-Access-Token": token,
                "Content-Type": "application/json"
            }
        }
    );
}
Enter fullscreen mode Exit fullscreen mode

Advanced Enhancements
1. Multi-warehouse packing logic
Calculate from which warehouse the stock should be deducted
2. Threshold alerts
Send notifications when inventory falls below a set threshold
3. Real-time sync dashboards
Display warehouse performance and reorder suggestions.
4. BigQuery Integration
Sync historical inventory logs for analytics.

Who Needs This System

  • Fast-Scaling DTC Brands
  • Multi-warehouse retailers
  • Fulfillment centers
  • Omnichannel businesses (retail + online)
  • Shopify Plus merchants with custom workflows

Real-time sync dramatically improves operations and helps avoid overselling during peak sales.

Many large merchants implementing systems like this work with a Shopify Plus Development Agency for architecture, webhook scaling, and secure API integration.

Final Thoughts

Building a real-time inventory sync system using Shopify+Firebase is one of the most effective ways to maintain accurate stock levels across multiple locations. Firebse's real-time capabilities combined with Shopify's robust inventory APIs create a highly scalable, efficient, and low-maintenance workflow suitable for modern ecommerce operations.

Top comments (0)