Webhooks & Google PubSub - Order by Date?

Hiya,

I’m using Google Pub-Sub to handle the load of Shopify Webhooks, they are then fetched in batches and delivered to the App using a simple script.

However.. if I’m not mistaken there’s instances whereby the Webhooks can be delivered in a different order than their date/time? We had a build-up of unacked hooks due to a bug, but when they were delivered we had some “order fulfilled” messages before the “order paid”.

Does anyone know of a way to force the subscription to order by the datetime of the event itself?

Thanks in advance.

1 Like

Hey @ceri_waters,

We don’t guarantee ordering within a topic or across topics for the same resource, so orders/fulfilled arriving before orders/paid can happen especially after a backlog clears.

To help with this, you can use the updated_at field in the payload to sort messages before processing them in your app.

On the Pub/Sub side, I’m not deeply familiar with Google’s internals, but I did find their docs on message ordering which might be worth exploring. It looks like they support ordering keys that could help ensure messages for the same order arrive in sequence.

Another approach is to design your processing to handle out-of-order events gracefully. For example, if you receive orders/fulfilled but the order isn’t marked as paid in your system yet, you could either queue it for later or just fetch the current order state via the API at that point. Treating webhooks as notifications and pulling the latest state on receipt is a pretty common pattern.

Our webhook best practices also recommend implementing reconciliation jobs that periodically verify your data matches what’s in Shopify, rather than relying solely on webhooks.

Thanks @KyleG-Shopify really helpful