Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New approach to handle the Shopify API rate limit. #20

Open
hillairet opened this issue Aug 26, 2021 · 1 comment
Open

New approach to handle the Shopify API rate limit. #20

hillairet opened this issue Aug 26, 2021 · 1 comment

Comments

@hillairet
Copy link
Member

I think I came up with a better approach to handle the Shopify API rate limit than the current one that tracks the number of available calls per API token.

  • I'll describe the approach storing everything in memory but it will work with something like Redis making it a scalable approach.
  • It will work exactly the same way for GraphQL and Rest. I'll use Rest as example.
  • The idea is to have a queue per API token storing the calls that hit the rate limit. The data structure (in memory) would be a dictionary with an identifier of the API token (store name for offline token and store name + staff id for online token) as keys and a python queue as value.
  1. The execute_rest method is called on an OfflineToken
  2. Start loop to check the dictionary for a queue and if there is a queue, check if it's empty or not, check the first element
    • If there is something in the queue, then queue a hash with the call parameters and WAIT 1 second
    • If the queue doesn't exist or it is empty or if the first element hash matches this call hash, then exit the loop
  3. Retrieve the token from the DB
  4. Execute the Rest API call and RETURN
  • The clear advantage here over what we are doing now is that when the rate limit is not hit, the call just goes through and nothing is stored in memory.

Comments and feedback please! 🙏

@hillairet
Copy link
Member Author

The API from this rate limit library could work here too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant