0

I am using an API that allows our app to make 600 calls to it per a minute. An import will allow a user to make as many calls to the API necessary to import all of their contacts. This is being tested with databases of up to 25,000 contacts. With each return from the API I am provided an HTTP header "X-Rate-Limit-Remaining" that tells me the amount of API calls left for that minute.

I am needing assistance developing an algorithm that will take into account the amount of contacts a user has and if needed, the amount of calls they have left for the minute. With this we would need configured how much time must be provided between calls to insure we do not go over our 600 calls/min. The API has provided an extremely farfetched example in python (I am using PHP) that would not be of much use in production.

Any help with this issue would be so appreciated!

  • It seems like it should be as simple as checking the `X-Rate-Limit-Remaining` header after each call and pausing before the next call if it drops below a certain threshold. – Don't Panic Sep 23 '16 at 13:55
  • 25000 / 600 = 41 minutes for processing 1 single database. So the next user may have to wait that long before his data starts being processed. You should have a mechanism to store the during this waiting period. – Kwebble Sep 23 '16 at 14:36
  • @Don'tPanic any idea on what that threshold should be. I'm a junior developer and this is really my first complex algorithmic problem I have to figure out so it's not coming to me as easily as most – Colin Rickels Oct 04 '16 at 12:35
  • @Kwebble OK so I could divide 25000 by 41 minutes and round down to figure out an approximate amount of Contacts to have synced per a minute. Now I just need to figure out how not to go over that given amount every minute – Colin Rickels Oct 04 '16 at 12:39
  • Theoretically, if you add a one second wait between calls if `X-Rate-Limit-Remaining` is less than or equal to 60, you should never exceed the rate limit. – Don't Panic Oct 04 '16 at 12:44
  • @Don'tPanic ok so 600/60 = 10. I could just make sure it does not exceed 10 syncs per a second and I would be fine maintaining the limit. That could actually simplify it a lot going with that formula. – Colin Rickels Oct 04 '16 at 14:34

0 Answers0