Using pub/sub with Gadget
I want to subscribe to the order webhook using google pubsub to handle the data since Gadget would be to expensive due to request time for me.
In the Shopify docs is described to add the permission as well as the webhook to the toml file. But the existing permissions from gadget are not in that file so I need to dublicate them every time I do changes there.
Is there an easier way / does the toml configuration change anything with the current Gadget Webhooks / other parts of Gadget? Thanks π
51 Replies
Could you please explain your use case and why you think it would be too expensive in Gadget?
I want to save the order in another database and we have millions of orders coming through. Basically I need to just push the order to another api. I tried that out a while ago with gadget actions and it increased my request time a lot. So I need to use pubsub
Do you just want to use Gadget as middleware? You don't need to use the data model if you're simply trying to push orders forward. Have you looked at these docs? https://docs.gadget.dev/guides/plugins/shopify/shopify-webhooks#adding-a-shopify-webhook-trigger-to-a-global-action
I have already used that for a similar use case in the past but it did cost me quite a lot. I had lot of those problems in the past with the request time so this time i went with pubsub.
Like would be a few million orders per month coming through
I'm not sure that I understand how it could have cost you that much. 10 million orders with extra logic only costs ~$185/month on the Pro plan. Are you sure that you were following best practices? If you would like me to help you get make your logic as performant as possible please let me know.
On the other hand, I've never worked with pubsub. You would probably need to register new webhooks and point them to it. Take a look at this thread for HMAC validation: https://discord.com/channels/836317518595096598/1335229513122185317/1335992113871061036

Got it, just in the past every time i was using it I had to pay a lot and once I had to pay like 600usd for a weekend. Maybe i can try it again though
I can share a cost optimization (work in progress) if youβd like to make sure that youβre doing best practices
That would be perfect
Google Docs
Copy of Cost opt docs
Separate account and billing into 2 sections (development-tools) Account β Account Management Billing β > Billing Cost optimization Cost optimization As your application grows itβs a good idea to begin to optimize it for to lower costs. BigCommerce Only store the data you need on models Do...
Please note that its a work in progress
Thanks
I was trying to disabled the webhook (orders/create) for the global action for specific stores. But it doesn't seem to work.
When trying to update with api.shopifyShop for disabledWebhooks you have to use internal API as far as I'm aware
Thanks. But this doesn't change anything neither unfurtunately. Is this correct?
`
But why isn't it changing anything? I get the correct response but it isn't changed in the db and also not filtering any incoming webhooks on the global action

Note that adding that disabledWebhooks field would deregister all webhooks for those models. I personally have your issue when testing it myself. The global action that I have didn't get triggered
Could you please share the URL of the application so that I can take a look?
https://keepcart-server.gadget.app
env: ricardo-dev
And yes, I want to disable all shopifyOrders webhooks since I only get the order/create webhook in the global action as a middleware
Ok, just coming back to this now. Let me see what I can find
On what action are you recieving the order webhook data?
Do you also mind if I make an env off of yours end test on my end?
sure π
middleware/ordersToTinybird
and then I am trying to change the disabledWebhooks on various places in the app (subscription change etc.) - but have deleted most of them again since it was not working
Side note: I noticed that you're on 24-10 and you can change to 25-01 without making any changes at all. I would recommend π
Thanks π I planned to change it and also change the gadget version soon.
Sent you a message privately about a bug I just ran into
How do I disabled the order webhooks from your app?
What exactly do you mean?
This is what I was trying to do.
But didn't work
My question is, do you have an action I should try using?
I'm able to do it with the JS Playground but what to see if there's some functionlity broken on your end
I was trying to do it in the subscribe action
On your app I still only see the shopifyCustomer disabled. Not the shopifyOrder

idk if that's cause you changed it back...
Interesting... I didn't
Its almost like the update isn't working
Even if I'm using the internal API
exactly. This is the issue I am having.
But the api request returns the correct value
Let me see what can be happening
Ok, something interesting just happened
I changed it manually in the database viewer then ran the internal update and it changed back
Almost like the call was not to the internal API somehow
Nvm, it looks like it changes by itself
hmmm, weird. Is that a bug you guys need to fix?
Just got some information that I need to test
Ok, so it looks like we're re-firing the action (with the public api) to change the registered webhooks field and the code that you put is changing the disabled webhooks value back
Sooo, I think that you should add a check to skip the logic if the registeredWebhooks field is the only thing changing
That would fix this for now
I'm making a ticket to audit this functionality. Basically what's happening is the following:
- internal api call to update disabled webhooks
- Gadget internal logic to register/de-register webhooks
- public api call from the Gadget platform to update registeredWebhooks
- record.disabledWebhooks is changed to { shopifyCustomer: true }
- triggers Gadget internal logic to register/de-register webhooks
- public api call from the Gadget platform to update registeredWebhooks
Thanks π
How would that work here?

Sorry, give me a moment. Writing a large ticket to explain a proposed change and whether or not making the change would break things for other users
Sure, no stress π
I think that you should do something like this:
This doesn't work unfortunately π¦
How so?

Running this and nothing changes in the db
You need to only put the record.disabledWebhooks bit in there. Also not that what I wrote isn't perfect
I asumed that you would have needed to change it
The second bit of that if is the issue in this case
You aren't hitting the logic in the if because changing disabledWebhooks is only one change
Still not working.

Basically trying to do that on the create action (and on others as well)
You're not doing what I'm telling you to do
Tried that as well

The create action can be whatever. Whats important is the update action
What I put results in the correct outcome:


thanks, seems to be working now
Note that this code now checks the first entry of the object and looks to see what the key is called
record.disabledWebhooks["shopifyOrder"] = false;
record.disabledWebhooks["..."] = false;
I am using this now. I think the issue was me overwriting it in my update code
Thanks for helping me out with this π