Skip to content

Rate Limit

Antoine CLOP edited this page Aug 1, 2020 · 3 revisions

Rate Limit

What is Rate Limit?

LeagueAPI uses Riot API to get its data. This service can be very busy since it provides informations to official League client, League web site and other many big web sites. To ensure servers are never overcharged (which could lead to lags and negative experience for players), Riot enforces rate limitation for calls on its APIs.

Since LeagueAPI is designed to offer a developer friendly experience, it handles key's limitations. Making requests often take a normal delay but if rate limit is reached, the framework will delay request until server authorizes new calls. For more details, there are two limitations: methods and region. With a developer key, you can make 20 requests per seconds to summoners in Europe West region. When limit is reached, you could then call summoners in Brazil region where your rate limit was not reached. But sometimes you're making too many requests to the same method, even on different regions. This could lead to a rate limit exceed too. You can show rate limit state by enabling. Debug logs in Logger (see Logger).

When developing your application with LeagueAPI you should think about how you use League's data cause it may impact performances. A good practice could be to save unique identifiers as they are used for a lot of methods. Like this you would save a request to get this identifier again.

Implementation

As mentioned above, LeagueAPI implements a system to prevent rate limit exceeded exception (that could lead to blacklist). Here is how it works:

When making a request to LeagueAPI, an internal check procedure starts, and will return an authorization status.
There are 4 different status:

  1. Refused: The rate limit is at its maximum and cannot send request now and is placed in a queue waiting for rate limit to permit new request.
  2. Accepted: The request can be sent immediately
  3. Exploring: LeagueAPI has no information about current rate limit status. The request will be sent immediately and subsequent calls will have the status of Delayed.
  4. Delayed: LeagueAPI's missing information about current rate limit and has already granted Exploring status to a previous request. Request will be attached to the Exploring request so that when it returns with current rate limit, LeagueAPI will re-evaluate request status.

When request to Riot API is sent, LeagueAPI will increment current rate limit so that it avoids situation like:

Before
Rate Limit: 99/100
###################
Sending 3 requests
###################
After
Rate Limit: 102/100 (Rate Limit Exceeded)

But instead LeagueAPI will do:

Before
Rate Limit: 99/100
###################
Sending 3 requests
###################
After
Rate Limit: 99/100 + 1 current request (100/100 when evaluated)
(2 following requests received Refused status as local information indicate that rate limit is reached)

🔒 Limitation 🔒

Such a system guarantees that rate limit should not be exceeded. But there is still one case that cannot be handled and it is related to the Exploring request. It is possible that this request reaches rate limit cause it was already at the maximum on Riot's side (but LeagueAPI just started and had no clue). It is in fact the point of this status: it is supposed to initialize LeagueAPI rate limit counter with current rate limit.

This situation is impossible to avoid since there is no API route to check current rate limit. The situation is similar to minesweeper's first move: you click on a cell but you have no indication on the game yet. Fortunately, the case where first request would exceed rate limit is unlikely to happen and even if it did, LeagueAPI will prevent any other request to be sent so your account will not be blacklisted.

Clone this wiki locally