-1

My client has two API keys for Alpha Vantage with a limit of 5 requests per minute.

If the limit on one is reached, then I want to use the other.

I am using MongoDB as a database.

I was thinking that we can store a variable in MongoDB, but I'm worried about the performance effects in that case.

What is the best (and simplest) way to do this?

The limit is 5 requests/minute. Requesting it to check if the limit is exceed might increase the total time the request takes to execute.

Akash
  • 762
  • 7
  • 25
  • Ok, and your programming actually question is? – Marc Mar 14 '23 at 13:10
  • Sorry if I wasn't clear. What is the best way to do this? – Akash Mar 15 '23 at 17:22
  • You want to use multiple API Keys? Ok. Whats the problem with it? Start coding. If key A returns "bad key", try key B. If that returns "bad key", you reached the rate limits of both API Keys. I dont see a programming question here. Whats your problem with doing it so? Your **programming** question. – Marc Mar 15 '23 at 19:06
  • The limit is 5 requests/minute. Requesting it to check if the limit is exceed might increase the total time the request takes to execute. This is why I asked if storing a variable in MongoDB to keep track of this is a good idea or not. – Akash Mar 16 '23 at 10:05
  • 1
    Dont check if the limit is reached. Just do your request when needed, and check the return status. When you made a request as needed, and you reached the limit, just use the other key – Marc Mar 16 '23 at 10:18
  • I see, thanks! If you post that as an answer, I'll be happy to mark it right :) – Akash Mar 16 '23 at 10:38

1 Answers1

1

You can make your requests as needed, and check the return code from the service.

If the service says/indicate "rate limit reached", try the second API key. If the limit of the second one is reached, try the first one again.

And so on.

PS:
There is no need "to check the key" if the limit is reached. Just make your API call as needed and check the return status.

Just try your keys in a round-robin routine when one reach its limit

Marc
  • 2,920
  • 3
  • 14
  • 30