Member-only story

4 Rate Limit Algorithms Every Developer Should Know

A beginner’s guide to implementing rate limit

Jason Ngan
Better Programming
5 min readJul 14, 2022
Photo by Wikimedia Commons

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.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (6)

Write a response