How to handle webhooks for fast product listing enabling and disabling

davidyzeng
Shopify Partner
6 2 1

Hi, I'm trying to manage product listings through webhooks product_listings/add, product_listings/update, and product_listings/remove. From my experience, product_listings/add and product_listings/update fire in less than a second while product_listings/remove takes 5-10 seconds to fire. 

 

The issue this raises is how to deal with someone enabling and disabling a product listing very fast, like click-click-click. product_listings/add and product_listings/update have an 'updated_at' timestamp field so I could compare against the latest timestamp and only respect the most recent timestamp. However, the product_listings/remove webhook only has the data shown below, with no timestamp. Therefore, I am getting these webhooks potentially out of order and I don't know which state the product listing is ultimately in. 

 

A solution that comes to mind is to poll Shopify, but then that kinda defeats the purpose of the product_listings/remove webhook and turns it into like an asynchronous poll request. My questions are:

 

1. Is there a guarantee that the webhooks will always come in correct order? Assume that I can correctly consume them in order received, is the last webhook the true state?

2. Can an 'updated_at' timestamp be added to the product_listings/remove webhook?

 

{
  "product_listing": {
    "product_id": 788032119674292922
  }
}

 From: https://shopify.dev/docs/admin-api/rest/reference/events/webhook?api[version]=2020-04

0 Likes
HunkyBill
Shopify Expert
4372 36 467

You are stuck in a rut here. First off, there is no real-time way to do your pattern. You cannot know a product listing has changed unless you listen to the webhook, and or, you keep polling for change. So there you have it.

So this begs the question, why are you in such a hurry? What is your use case where you need instant gratification?

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
davidyzeng
Shopify Partner
6 2 1

Hi, thanks for the response. It's not that I'm in a hurry, but more about the UI/UX of the sales channel. I let users enable/disable product_listings in my app and right now the best idea I have is to debounce the clicks with a 5 second delay so that I'm not triggering race conditions with Shopify webhooks. However, this is a worse UX because people should be able to click the enable/disable buttons at will and the app should ideally be able to handle it.

0 Likes