Тёмный

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

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

Token bucket Rate limiter is another algorithm which we can use to implement rate limiting. It helps in protecting API from abuse. This is a continuation of previous video where I have explained Leaky bucket rate limiting.
0:00 Introduction
0:25 Token Bucket Rate Limiting Implementation
1:02 Token Bucket Class implementation
8:21 Bucket Creator Class Implementation
9:15 Run Implementation
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

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 11   
@rams2478
@rams2478 2 года назад
Thanks for sharing. Easy to understand.
@amanchoudhary9107
@amanchoudhary9107 Год назад
it will have race condition , for ex Thread T1 and T2 are executed concurrently ,T1 executed line 34 and moved to 24 and passed meanwhile T2 was waiting at line 34, it will again update the count to 10.
@subhajitmanna305
@subhajitmanna305 2 года назад
Let's talk about a situation when one thread is updating the currentCapacity the other thread can read the last updatedTime so similarly vice versa. So a race condition will raise. I think we need to synchronise the refresh method;
@bavmac
@bavmac 2 года назад
Do i need to use concurrent hashmap for multiple users?
@tirupatirao7521
@tirupatirao7521 2 года назад
what abt distributed instances of gateway and isolated service centers?
@harshitaagarwal4770
@harshitaagarwal4770 Год назад
I think the logic of calculating additional token is wrong. Lets say the user request after 4 seconds, according to the logic 4*refresh rate token will be added in the bucket. Isn't it wrong? Will the token be carry forward if there is no request for some seconds? For that seconds 40 token will be added for refresh token 10 but, only 10 requests should be there for that particular second. Also in real life solution for API calls how can we implement it? Using cache?? We will need a persistent hashmap.
@VirendraSingh-fj2hi
@VirendraSingh-fj2hi Год назад
Creating Map for every user is not required right, we can create map as static.. Ideally user same userBucketCreater will be called only once for one user
@himanshusingh3056
@himanshusingh3056 2 года назад
Don't we need to sychronize refresh bucket method? AtomicInteger does not prevent race condition, any other thread can change its value in middle of execution.
@TheTechGranth
@TheTechGranth 2 года назад
Race condition is simulated in the example with 10 threads
@cactusbee8474
@cactusbee8474 2 года назад
Doesn't this code updates the lastUpdatedTime variable in refreshbucket() even if additionalToken evalutes to zero? Anyways, your LLD videos are really good. Great work!
@chengdongli6386
@chengdongli6386 2 года назад
It should be ONLY updated if additionalToken>0
Далее
Rate Limiting - System Design Interview
24:04
Просмотров 27 тыс.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27