How to rate limit your HTTP requests with HttpQueue (for beginners)

HTTP Queuing

Rate limiting is when a server or API rejects your requests (e.g. to post to a discord webhook) if you’re sending them too much. Think of it as a bank:

If a bank has to deal with many customers in a day, they are going to be very busy. The bank can deal with everyone and their request very quickly. Now lets say there is a customer who needs to go to the bank a lot. They keep going back to the bank a lot of times and take up everyone elses time while the bank deals with their request. Eventually, the bank will say no and make you wait for a while until you can do your next transaction.

This is the similar premise to a server, where it will time you out from asking them to do something for a specific amount of times.

This application can help out with making sure you spread out you requests, preventing you from being rate limited (credit to @davness)

How to use this in your system

HttpQueue.rbxm (28.4 KB)

  • Drop the “HttpQueue” script into ServerScriptService and move over to your webhook script.
  • Replace your script with the following, making changes to the script where appropriate:
local webhook_link = ""

local JoinMessage_Queue = Http.HttpQueue.new({
    retryAfter = {cooldown = 10}, -- How long you should wait until trying again if it rate limits you
    maxSimultaneousSendOperations = 5 -- A suitable amount for discord, tells the script how many items from the queue it can send in one go
})

players.PlayerAdded:Connect(function(plr)
	local data = {} -- Your message information can go here. For info. check out https://leovoel.github.io/embed-visualizer/
    local request = Http.HttpRequest.new(webhook_link,"POST", nil, data) -- Create the information for our request so that we can queue it
    JoinMessage_Queue:Push(request):andThen(function(response) -- Here is where the info for the person who joined is lined up waiting to be sent to your Discord webhook.
        print(response.StatusMessage) -- This tells you if it worked or not.
    end)
end)

What if some big hotshot VIP joins my experience and I want to know first?
You can push specific requests the queue. With this, you can check if their name is a big important person and make their request a priority, meaning that they will be the next to have their message sent even if they joined after others.

JoinMessage_Queue:Push(request, Http.HttpRequestPriority.Prioritary)

This should do the trick, tinker around where needed and play around with the timings at the top of the script if this doesn’t solve your issue immediately.

Example code by @davness, altered for the less experienced and to work with Discord. In no way do I take any credit.

12 Likes