Rate Limit Of Shopify API And Its Impact
What is Shopify API and use for?
Let’s know what exactly the API is. API stands for Application Programming Interface. It allows developers to fetch and process data, enhance existing functionality through other applications without need for developing them from scratch.
Shopify provides various types of APIs which can be used for fetching, processing, and extending functionalities in Shopify. Each API requires access permissions. For access permissions you can refer to another blog on Access permission for Shopify API.
Every APIs has its rate limits which can impact on your development.
What are API Rate Limits?
As multiple APIs can be run at the same time which will create chaos at Shopify server as there will be multiple requests from different different APIs at the same time it will lead to downtime of the server. To avoid this Shopify rate limits APIs to maintain stability on the server.
There are various rate limits:
API | Rate-limiting method | Standard limit | Advanced Shopify limit | Shopify Plus limit | Shopify for enterprise (Commerce Components) |
GraphQL Admin API | Calculated query cost | 100 points/second | 200 points/second | 1000 points/second | 2000 points/second |
REST Admin API | Request-based limit | 2 requests/second | 4 requests/second | 20 requests/second | 40 requests/second |
Storefront API | None | None | None | None | None |
Payments Apps API (Graphql) | Calculated query cost | 910 points/second | 910 points/second | 1820 points/second | 3640 points/second |
Customer Account API | Calculated query cost | 100 points/second | 200 points/second | 200 points/second | 400 points/second |
Leaky Bucket Algorithm
For managing API requests Shopify uses a leaky bucket algorithm. Now let us understand what a leaky bucket algorithm does.
Whenever any API requests data from Shopify it makes load on servers. For controlling this load Shopify follows Leaky Bucket Algorithm which allows it to make multiple requests without overloading the server.
Each app allotted a bucket which can hold 40 calls having leak rate 2 calls per second and for Shopify plus store 400 calls having leak rate 20 calls per second which empties the bucket. If the bucket has space the request will be processed instantly.
If the limit is reached the remaining requests will be queued until the bucket gets empty.
Rate Limiting Methods
- Request-based limits
App can create a max number of requests/minute.
E.g 40 requests / 60 seconds.REST Admin API uses this method. - Calculated query costs
App can create a request that costs a maximum number of points/minutes.
E.g 1000 points / 60 seconds.
Graphql Admin API uses this method.
Cost Calculation
The cost of a query is calculated on basis of maximum possible fields selected.
The cost of a query is calculated on the basis of maximum possible fields selected.
Field returns | Cost value |
Scalar | 0 |
Enum | 0 |
Object | 1 |
Interface | Maximum of possible selections |
Union | Maximum of possible selections |
Connection | Sized by first and last arguments |
Mutation | 10 |
Shopify calculates cost before and after execution.
- The requested cost based on fields opted in the request.
- The actual cost based on the query result.
Rate limits combine the requested & actual query cost. Before processing the bucket must have capacity for the requested cost of a query. After processing the bucket is refunded with a difference between the requested cost and actual cost.
Impact of Rate limits
- If the API request is not handled it can lead to downtime which can impact server performance, which means your app will not function properly.
- If the rate limit exceeds it can lead to errors,Upgrade slow loading and API can be temporarily restricted.
- Developers have to plan API usage very carefully taking rate limits as a consideration.
Strategies to manage rate limits
- Improve API requests.
We need to use only required API calls and eliminate the ones which are not required. - Integrating various API in one: We can integrate various API in one to get the required information together instead of asking one by one which eliminates the number of times the API runs.
Storing responses: Storing the responses locally and using it for other API can reduce load on API and can enhance performance.
- Observe & look over usage of API: Observe the queries or excessive requests which are creating the issues. Knowing the root cause can help it out to solve the problem.
- Take time while requesting: Use strategies like taking time between API requests can help to maintain the rate limit. Along with this try to use some libraries and tools available for rate limit management.
- Upgrade to higher shopify plans.
- Use bulk operations.
Conclusion
Rate limit is very important and crucial in app development. One cannot neglect it. By following the best practices and following the restrictions can manage the API rate limits and boost their ecommerce business.