We have a Laravel based application which is hosted in AWS.
We already setup Shopify to send request to this app (postcode/shipping address) and get the 10 closest stores around the shipping location.
Shopify sends this request to our app when customer fills up and submit the Delivery address form and goes for payment page.
This works fine but the issue is, if customer goes back and forth between checkout pages (delivery address and payment page), Shopify send the request again and again (interestingly, the extra requests won't appear in the browser inspector!).
For each request, our app makes 10 Google Maps API calls to get the distance between the stores and the shipping location and then return the list of stores back to Shopify. This made our google bill so high (couple thousands per month!).
I need a way to prevent Shopify to send request to our app, if that already happened. I am not sure whether it's possible to cache the API response in Shopify to avoid sending extra request to the app if the address/postcode is still the same?
I highly appreciate if your could help me how to fix the issue.
If you're using webhooks, Shopify already de-duplicates webhooks when multiple actions occur within a 10 second period. For any updates that occur more than 10 seconds apart, the expected behaviour is that a webhook will fire. In this case, you may want to consider implementing some logic in your app to prevent sending extra calls to the Google Maps API if you receive webhooks with the same address.
Just to clarify, as of today, the logic behind de-duplication has changed, so webhooks are no longer delayed for 10 seconds before sending