🖥️Rate Limit (Like a pro)

Introduction

In this section we will walk you through how to get started with Sixth rate limiter and also demonstrate using an example of how to do this. By the end of this section you should be comfortable with using Sixth in your backend applications.

Rate Limiting by endpoint (The Magic of Sixth Rate Limiter)

With the Sixth we allow you rate limit by endpoint, hence giving you the ability to customise how many times a particular endpoint can be called in a certain window of time. Every endpoint by default allows 10 requests in a window of 60 seconds and is deactivated for every endpoint unless you manually activate it, this means only 10 requests in 60 seconds is allowed by default to anyone of your endpoints if you activate it. Let's say you have an endpoint called /resend_otp/ and you want to override this default behaviour and customise it to be only 1 request in 60 seconds. Lets see how this can be done

Step 1

Head over to your dashboard and select rate limiting, you should see all your endpoints listed listed, after clicking on the rate limiting tab in the dashboard we should have the following.

In our case we are only interested in the /users/resend_otp/ endpoint.

Step 2

Click on the /users/resend_otp/ and you should see this

For now we will focus only on the rate limit and interval fields. So here are a few things to know about these fields.

  • Rate Limit: This field is responsible for controlling how many times your API will be called in certain Interval.

  • Interval: This field is responsible for the setting the time interval for with your rate limit is valid. Please note that this is measured in second, and in order to rate limit by milliseconds or nanoseconds, the appropriate conversion should be done.

Now that we finally what these fields mean. Let's go back to our use case, we want to only process 1 in request every 60 seconds for the /users/resend_otp/ endpoint, can you guess what the values of the rate limit and interval field will be? If you guessed 1 for rate limit and 60 for interval you are absolutely correct!. After making these changes we click on submit and head over to Postman.

This shows the response when we try to call the endpoint for the first time, let's see what happens if we try call the endpoint immediately afterwards.

As we can see this request was blocked and we got the 420 status code and a message which indicates that we have reached the maximum request we can make in 60 seconds.

Now that you know how it's done, go ahead and rate limit your endpoints as you wish, good luck and may the Sixth be with you!.

Last updated