Skip to content


Repository files navigation

Proactively Stocking Inventory using ML


How do you notify store associates when items are out of stock? What if you could leverage footage from in-store cameras to detect when stock is low for items that have a quick turnover (like produce) and have those refilled before running out?

In this session from Google Cloud Next 2018, we walked through an architecture that describes how to combine camera footage, the Cloud Vision API, and Firebase to deliver an end-to-end use case to help shoppers get the products they need without having to wait.


Demo Architecture

Process Flow

  • Images are uploaded to a Cloud Storage bucket
  • Cloud Storage bucket notifications are sent to a Cloud Pub/Sub topic
  • Cloud Pub/Sub push subscription sends message to App Engine Inventory service
  • Inventory service sends image to Cloud Vision API
  • Based on Vision API response, Inventory sends message to a Pub/Sub topic
  • Cloud Pub/Sub push subscription to App Engine Messaging service
  • Messaging service uses Firebase Admin API to send device notification
  • Firebase delivers push notification to Staff App



App Engine

$ gcloud app deploy \
default-service/app.yaml \
inventory-service/app.yaml \

Cloud Storage and Cloud Pub/Sub

Edit with the following information:

  • Cloud Storage bucket name (BUCKET_NAME)
$ ./ all up


In the Firebase console for your project, navigate to Project Settings > Cloud Messaging and create a new Web Push certificate. Next copy the Key pair and paste it into messaging.usePublicVapidKey() in staff-app/index.html.

$ cd staff-app
$ firebase deploy

Once the Firebase app has been deployed, navigate to it and generate a new push token. Copy that token and run the following:

$ ./ [TOKEN]