SHOPIFY rate limit? Explanation of Leaky Bucket Algorithm and GRAPHQL with illustrations
Hello! This time, it is an article explaining about SHOPIFY rate restrictions and GraphQL. I will explain without using difficult expressions so that the question "What is rate limit?" "What is graphql?" However, some unfamiliar words may come out. especially API It is a premise that you can understand a little about a little, so if you have never heard of the word API, please study a little by watching YouTube videos.
REST API and GraphQL
SHOPIFY has two types of API (Admin API) for acquiring, creating, updating, and deleting customer information and order information, Rest API and GRAPHQL.
I will explain the difference between REST API and GraphQL in SHOPIFY. It is not a specialized content, but it is only explained to grasp the shape, so please check it out for details.
This time, I will explain Shopify's customer information as an example.
Rest API
For example, if you want to know the name and address of a certain customer, you can use the SHOPIFY REST API.
The side to call the API "Please give me information on the customer number XXXX"
SHOPIFY "Customer number XXXX number information" (all in name, address, number of purchases, purchases, etc.)
As described above, Shopify returns data with "put all" even if you only want a specific information. Based on the returned data, the processing out only the necessary information is required for the call of the API.
https://shopify.dev/docs/api/admin-rest/2024-07/resources/customer
Graphql
If you want to know the name and address of a certain customer, like the REST API, this is the case with GraphQL.
The side that calls the API "Please give me information on the customer number XXXX number Email, name, and address"
SHOPIFY "Customer number XXXX number EMAIL / Name / Address is here"
In this way, it is possible to acquire only the necessary information. Of course, you can get not only name and address but also information such as the most recently purchased products.
https://shopify.dev/docs/api/admin-graphql/2024-07/queries/customer
Very very much, I explained the difference between REST API and GraphQL in SHOPIFY. Please keep in mind that this difference will be involved in the rate restrictions we will talk about in the future, so it is okay to just blur.
SHOPIFY rate limit
SHOPIFY has a rate limit, and its limits are slightly different between REST API and GraphQL.
What is rate restriction ...?
In the first place, the rate limit is that the API provider (in this case, SHOPIFY) is a mechanism that restricts the number of API requests that can be made within a specific time frame.
As shown in the figure below, if you are unlimitedly accepting requests such as "Give me that information", "Give this information", "Please add this information", high load on the API server. The system may not work properly.
In order to avoid the crash of unintended server, there are various rate restrictions in services that provide data as well as SHOPIFY.
SHOPIFY rate limit
REST API rate limit
The REST API is a request -based limit, and the standard limit is up to 2 requests per second.
What does this "1 request" mean?
Take GET information
Add post information
Delete Delete information
Edit PUT information
Each one is one request, and if you want to get 10 information, 10 requests, 1 request if you delete one information.
It's very simple.
GraphQL rate limit
The restriction of the REST API was very simple. So what about GraphQL restrictions?
In the figure above, the method is described as "Calculled Query Score" and "100 Points/Second". What does this mean ...?
GraphQL does not calculate "one information = 1 request".
When calling the API Object acquisition is "1 point" 、 Mutation requests to update, create, and delete data is "10 points each" It is.
https://shopify.dev/docs/api/usage/rate-limits#calculated-query-costs
20 information Just get it If so, a total of 20 points. It is possible to process without any problem within the limit of "100points/Second".
So Update 20 information What to do? Mutation is 10 points per case, so 20 points are calculated.
The REST API may feel a little complicated because it is too simple, but I think the GRAPHQL point calculation is easier than expected.
Even if you look at the above numbers, you feel that GraphQL is more efficient than the Rest API. SHOPIFY officials also recommend using GraphQL.
If you have never touched it, it may take some time to learn, but let's try it.
Hole bucket
"Hole bucket" is a splendid IT term. You may have heard of the word "Leaky Bucket Algorithm" in the name of the English name ...?
Leaky bucket algorithm is one of the algorithm when processing rate restrictions.
The request is processed like a bucket with a hole.
REST API bucket
The size of the bucket that can be processed at once, the size of the bucket is 40 requests (shop units / application units), which is leaked by 2 requests per second.
If you explain it roughly, it looks like this. Not only the type of request, but also "1 request", so it is easy to return the Too Many Requests error as the number increases.
GraphQL bucket
The bucket size of GraphQL is 50 Points leak per second in 1000 Cost Points (shop unit / application unit).
The expression feels a little complicated, but the idea is basically the same as the REST API.
We sent the same number of requests as the REST API, but in the case of GraphQL, more data can be processed because the bucket is still enough.
In the above example assuming that the request of the Mutation was sent, but if this is a query that only data acquisition, the request point of the request is one -tenth "1 point", so there is even more room. It will be the situation.
Compared to the REST API, the cost is much lower, but if you try to process a large amount of LINE ITEMs one by one, the rate limit will be more likely to be applied.
As a solution, SHOPIFY's GraphQL also has a Bulk Operation asynchronous lump -sum processing method.
https://shopify.dev/docs/api/usage/bulk-operations/queries
If you have created a custom app but have a restriction on it, or if you have any problems such as wanting to speed up the processing, please contact Go Ride.
Learn GraphQL and efficiently use Shopify data
The REST API is relatively simple, and I think anyone who has learned a web application may have touched it once. If the required amount of data and the number of APIs are small, the REST API can operate the application sufficiently.
On the other hand, GraphQL is a slightly special method, but if the data type and amount of data, such as SHOPIFY, are large, can efficiently handle data.
In addition, GraphQL is also recommended by SHOPIFY formula. At first, the hurdles are a bit high and the learning costs cost, but if you are interested, please study.
Various commentary videos are released on Shopifydevs YouTube channel of Shopify. I am very indebted to me, and I am also referring to this article.
The hurdles are a little high because it is full -length English, but if you are worried, please take a look.
https://www.youtube.com/@shopifydevs
Utilize SHOPIFY even more
This article was a little specialized content. To be honest, if you just open the store in SHOPIFY and operate it, it may not be much needed.
However, the possibility of SHOPIFY is infinite! You can expand the store more and more as you like.
Of course, the introduction of the applications that are already prepared by the SHOPIFY App Store, but if you are in your own demand, it might be a good idea to use API to create custom applications ...?
If you are worried about building a SHOPIFY store, please contact Go Ride. We will help you propose and build applications that suit your store!