Тёмный
No video :(

System Design Rate Limiter | Leaky Bucket Implementation | System Design Interview 

The Tech Granth
Подписаться 20 тыс.
Просмотров 11 тыс.
50% 1

Rate Limiter protects an API from abuse by restricting a user form making a limited number of request in a given period of time.
In this video I am going to discuss about the implementation of a thread safe rate limiter
0:00 Introduction
0:12 Rate Limiter Basics
2:53 Components Involved
5:03 Leaky bucket Implementation
9:15 Bucket creator
13:45 Single instance rate limiter
15:32 Multithread rate limiter
19:05 Distributed rate limiter
You can buy us a coffee at : www.buymeacoffee.com/thetechg...
system design: • System Design | Distri...
DS for beginners: • Arrays Data Structures...
leetcode solutions: • Leetcode 84 | Largest ...
github: github.com/TheTechGranth/theg...
facebook group : / 741317603336313
twitter: / granthtech

Опубликовано:

 

31 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 23   
@shervilgupta92
@shervilgupta92 2 года назад
Do we need the capacity check, I think the add method will throw an exception in case of no remaining space in the queue. Can we wrap this in a try catch and return the exception instead of false ?
@mehulparmar9976
@mehulparmar9976 Год назад
You are not removing requests from bucket! Need to fix this code.
@sudhanshukumar-yu7fj
@sudhanshukumar-yu7fj 2 месяца назад
He did say that in the real world services would consume the items from the queue
@gursharanaulakh6882
@gursharanaulakh6882 2 года назад
Thanks for the explanation. I see a few corrections in your implementation: 1. UserBucketCreater should not be initialised for each and every user. In the constructor you are keeping Map which is initialised per user and for every user there will be one map with only one key. The map will be initialised for the whole app and should have different LeakyBucket per user. 2. If there is no entry in the map for a specific user, we have to add one and the increment.
@TheTechGranth
@TheTechGranth 2 года назад
How will you scale this implementation? What happens when we have application running on distributed server?
@gursharanaulakh6882
@gursharanaulakh6882 2 года назад
Yes, that's what my point is, a local map will be replaced by redis and then each user in redis will have a separate bucket. Here you are initialising map every time as part of UserBucketCreator and it should be common to the application, be it local or distributed. Am I missing something?
@aniruddhkhera510
@aniruddhkhera510 Год назад
Great implementation and very well explained! I think one minor fix on the code, instead of initializing the map in the BucketCreator constructor, you could take the map as a static variable.
@WeilongYou
@WeilongYou Год назад
This doesn't look like a leaky bucket? You are not leaking requests at a fixed rate.
@lemonginger001
@lemonginger001 Год назад
yes this is shitty bucket
@aneksingh4496
@aneksingh4496 2 года назад
lets say you are using redis for distributed cache ...would not we have race conditions there ? if yes how to deal ?
@Rohit-hs8wp
@Rohit-hs8wp 6 месяцев назад
Buddy, you have to make the UserBucketCreator Map to be static otherwise your Map will only contain 1 userEntry.
@abhinabroy4803
@abhinabroy4803 Год назад
Nice video. Thanks. I had a small doubt, shouldn't the type of bucket be Map instead of Map ? For strategy pattern we should not use concrete definitions. What do you think?
@priyankataneja7347
@priyankataneja7347 9 месяцев назад
I have few questions here, In non distributed system when u had leaky bucket for every IP and you restrict 10 request per min from 1 IP. Lets say queue size is 20 and we get request from multiple IP's and queue gets filled for first IP we could use only 3 requests out of 10 and queue got filled, it still had quota but it is not allowed to send the request, Is this correct, Please correct me if my understanding is wrong here.
@mysymbol
@mysymbol 2 месяца назад
there is " leaky bucket for every IP" which means there is a blocking queue for every IP. In a queue size of 20, queue can not reach it limit with just 3 requests from that IP. It will still have the quota for that IP and it will allow
@ranjithk9638
@ranjithk9638 Год назад
try testing this with more than one user and multiple requests.
@kapilarora4415
@kapilarora4415 2 года назад
good one, can you share the code link?
@TheTechGranth
@TheTechGranth 2 года назад
GitHub link is there in description
@ankitnigamrocks
@ankitnigamrocks 2 года назад
Good One. But couldn't find any where you removing the elements from blocking queue. Am i missing something?
@TheTechGranth
@TheTechGranth 2 года назад
You are right. I did not add any consumer, to keep the focus on leaky bucket implementation, rather than complicating it into a producer, consumer model.
@ankitnigamrocks
@ankitnigamrocks 2 года назад
@@TheTechGranth Noted Thanks :)
@TheTechGranth
@TheTechGranth 2 года назад
@@ankitnigamrocks Hope it was helpful. Do like and subscribe and share with others 🙂
@ankitnigamrocks
@ankitnigamrocks 2 года назад
@@TheTechGranth yes i liked. Am i already a subscriber. You are doing good job. Keep up. Thnxks
@ashishkarn068
@ashishkarn068 2 года назад
One Could simply add a AtomicLong lastLeakedTime & Leak() method. Inside Leak(), take() from blocking queue number of expected leaks till now.
Далее
Best exercises to lose weight ! 😱
00:19
Просмотров 10 млн
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Rate Limiting - System Design Interview
24:04
Просмотров 27 тыс.
Rate Limiter with Sliding Window Algorithm
10:27
Просмотров 5 тыс.