DEV Community

Rafael Lourenço
Rafael Lourenço

Posted on • Edited on

Understanding the Leaky Bucket Problem with Redis

In my path to become a software engineer, I was challenged by my mentor @sibelius to demonstrate how I implement the leaky bucket with this API documentation.

To work on that i started drawinng on Excalidraw and got this design.
leaky-bucket design api

Understanding this picture is pretty simple; all the queries are going to hit Redis to check if the information already exists in memory. If the information exists in memory, we get the answer back. If not, we have to check if we have 'coins' in our bucket to make a query to the DICT API and get the answer back to the client. We then save that in Redis. If our bucket is empty, we don't call the DICT API and respond with a rate limit.

This initial application will have a very simple calculation for bucket usage:

Status 200: Remove 1 coin
Status 400: Remove 20 coins
Bucket refill: 2 coins per minute
Bucket size: 100 for individuals and 1000 for legal entities

Top comments (0)