-1

I am attempting to use the riot-api to build statistics pages for different players. The algorithm works after a specific player is identified, then an api call will attempt to fetch about 15 games. I then want to iterate through this list of 15 games where for each game, I need to make another api call to pull that matches specific game data. The game data then gets saved to cloud firestore. I choose to get about 15 games at a time because the riot api limits to 20 calls a second, and 100 calls every 2 minutes. The issues is I am going through all the algorithm too fast and I am getting a 429 error because I am hitting the limit. Is there a way to slow down the rate of my api calls to stay in the window or is there a better way to deal with the 429 error like a retry?

Đăng Khoa Đinh
  • 5,038
  • 3
  • 15
  • 33
Dan
  • 1
  • 2
  • Does their API allow you to fetch all the relevant information in one single request instead of having to make multiple calls for each player? – Mike May 08 '21 at 21:30
  • Why not make new calls only after the first batch is resolved? – T J May 08 '21 at 21:59

1 Answers1

0

You can use Cloud Tasks for rate limiting your calls to the riot-api. There are a couple of ways to achieve this...

  1. Create a Callable Function (in Firebase) and use this to write your requests, then have the function add them to a Cloud Tasks HTTP queue with a rate limit.
  2. Write the data to Cloud Firestore/ RTDB, which triggers a Cloud Function to add the request(s) to a Cloud Tasks HTTP queue with a rate limit.

Create another HTTP Cloud Function (the worker) to receive tasks from the queue, call the riot-api and write the data to Cloud Firestore. If you receive an error from the riot-api, the task will retry. Cloud Tasks will automatically reduce the rate of retries to avoid overloading your endpoint.

Jason Berryman
  • 4,760
  • 1
  • 26
  • 42