Member-only story
4 Rate Limit Algorithms Every Developer Should Know
A beginner’s guide to implementing rate limit

If you have dealt with any backend services before, you have probably heard of the term Rate Limit.
Without this crucial toolkit, clients can make as many requests as they want to your service at any point in time. This leads to a sudden traffic spike, thus, hoarding your servers.
In this blog post, let’s return to the fundamentals and discuss the four commonly used rate-limiting algorithms.
Let’s get started!
Token Bucket
The token bucket is one of the easiest to implement among the other four.
Let’s take a look at the simplified steps.

- Imagine having a bucket containing
N
number of tokens - If a request arrives, we take one token out from the bucket and process the request
- Supposed there’s no token left, we discard and do not process the request.
- At every fixed interval, we replenish the tokens in the bucket back to
N
number.