discord_ex icon indicating copy to clipboard operation
discord_ex copied to clipboard

handle Rate Limits in some "good" way

Open Marqin opened this issue 9 years ago • 3 comments

RATE LIMITS docs (it's on github, link on web docs is broken)

Discord's dev request for lib developers to handle Rate Limiting properly

Marqin avatar Aug 27 '16 13:08 Marqin

So, the simple way to implent:

We could have some "global state" implemented via Agent (or process) that is registered to atom name. And now, when geting REST reposnse we upgrade that "state" to current rate limit info. And when doing REST request we can:

if curr_time() < RateLimit.get(:rate_limit, "refresh_time") and RateLimit.get(:rate_limit, "req_left") == 0 do
  {:error, "You have been blocked by RateLimit feature."
else
  # send our request
end

Marqin avatar Aug 27 '16 13:08 Marqin

I could start working on it when we agree on some architecture.

Marqin avatar Aug 27 '16 13:08 Marqin

rate limiting:

HTTP

  • X-RateLimit-Remaining will tell us how much more requests we can do
  • X-RateLimit-Reset will tell us when RL timer resets

WS

  • sending limit: 120 events / minute

Game Status:

  • 5 statuses / minute

Gateway connection:

  • 1 connection / 5 seconds, but: if you hit this limit the Gateway will delay your connection until the cooldown has timed out

Marqin avatar Aug 27 '16 14:08 Marqin