How to handle shopify admin API calls rate limit in django app

I have a shopify app that built in django app with some celery workers, each worker can send a lot of request to shopify and the types of request have several priority in my app, now I want to build a shared priority queue between workers for each store to handle shopify rate limit and priority:

celery worker 1:

import shopify 
import time

# update more than 1000 of variants 
for variantId in variantIds:
    time.sleep(0.5)
    with shopify_session(store.domain, store.token):
        shopifyVariant = shopify.Variant.find(variantId)
        # here some cahnges on variant
        shopifyVariant.save()

celery worker 2:

import shopify 
import time

# update store info
for store in stores:
    time.sleep(0.5)
    with shopify_session(store.domain, store.token):
        shopInfo = shopify.Shop.current()
        # update shop info in app database

web app:

class TagList(APIView):
    @generate_shopify_session
    def get(self, request):
        try:
            data = ShopifyGraphQl().tags()
        except BaseException as err:
            return JsonResponse({"message": str(err), 'success': False})
        return JsonResponse({"data": data, "success": True})

These are a few examples of api calls in my app that can be called in one second and shopify will response with 429 too many request status code

What is the best architecture for implement queues and handle the shopify rate limit?

Back to Top