access icon indicating copy to clipboard operation
access copied to clipboard

use Okta's response headers for rate limits

Open gabrielsroka opened this issue 1 year ago • 1 comments

transcript of (Gabriel's half of) a conversation with @somethingnew2-0

why do u use exponential backoff when Okta tells you when u can retry the api call? https://github.com/discord/access/blob/40d8c0b2e19a0783430cfdac0834c4d893356cc0/api/services/okta_service.py#L41-L66

if u get a 429 error that tells u when to retry, why not look at those headers? eg (and this isn't perfect, but...) https://github.com/gabrielsroka/gabrielsroka.github.io/blob/master/console/index.html#L169-L187

ie, if u reach the rate limit at 10:00:00 and it tells u to retry at 10:01:00, there's no point in retrying at 10:00:01.2, 10:00:02.4, 10:00:04.8. ur just gonna get more errors

Okta provides three headers in each response to report on both concurrent and org-wide rate limits. For org-wide rate limits, the three headers show the limit that is being enforced, when it resets, and how close you are to hitting the limit: X-Rate-Limit-Limit - the rate limit ceiling that is applicable for the current request. X-Rate-Limit-Remaining - the number of requests left for the current rate-limit window. X-Rate-Limit-Reset - the time at which the rate limit resets, specified in UTC epoch time (in seconds).

https://developer.okta.com/docs/reference/rl-best-practices/#check-your-rate-limits-with-okta-s-rate-limit-headers

gabrielsroka avatar Mar 28 '24 16:03 gabrielsroka

Perhaps _retry() can use the Okta python SDK's built-in 429 retry

exitcode0 avatar Apr 06 '24 14:04 exitcode0