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

Поділитися
Вставка
  • Опубліковано 5 вер 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;

  • @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.

  • @himanshusingh3056
    @himanshusingh3056 2 роки тому +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

  • @tirupatirao7521
    @tirupatirao7521 2 роки тому

    what abt distributed instances of gateway and isolated service centers?

  • @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

  • @bavmac
    @bavmac 2 роки тому

    Do i need to use concurrent hashmap for multiple users?

  • @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