Thursday, February 9, 2023
HomeOtt NewsRate Limiter : Protecting Hotstar APIs from abuse | by Subhojit Dutta

Rate Limiter : Protecting Hotstar APIs from abuse | by Subhojit Dutta

Free Timer — Non Trivial Tech

Free-timer flow (backend)

Preventing Abuse

Lyft Rate Limiter-POC

# algorithm: IP based rate-limit config of 10req/min on "/login" API1. time_now = current_time()
2. rate_limit_window = 60 //since rate limit is per min or 60sec
3. req_ip = incoming_request.ip
4. bucket_id = time_now / rate_limit_window
5. redis_key = format(login_%req_ip%_%bucket_id%)
6. key_ttl = (bucket_id + 1) * rate_limit_window
7. pipeline two redis commands:
INCR redis_key 1
EXPIRE redis_key key_ttl // SET TTL
8. current_count = INCR-command.result()
9. if current_count > 10, return 429 (over limit)

Key formation algorithm changes

# new algo: IP based rate-limit config of 10req/min on "/login" API1. time_now = current_time()
2. rate_limit_window = 60
3. req_ip = incoming_request.ip
4. redis_key = format(login_%req_ip%)
5. pipeline two redis commands:
"INCR redis_key 1"
"TTL redis_key" // get TTL of the key
6. if TTL-command.result() = 0, // no TTL set yet
a. key_ttl = time_now + rate_limit_window
b. send redis command "EXPIRE redis_key key_ttl"
7. if INCR-command.result() > 10, return 429 (over limit)
Image depicts the change in window spans (start and end TTL). The dotted lines are 10s apart. We see that in old algorithm, a T20 and a T55 request (green ones) both fell in the bucket which spanned from 0–60. This meant both the keys expired at the same time. In the new algorithm, the start time (T) determined the TTL.
Vertical load test results

Some other changes

Source link

Latest articles

AICTE Invites Application to Translate SWAYAM Online Courses

The All India Council for Technical Education (AICTE) has released a notice inviting...

Andy Murray Grabs Wildcard To Compete At Dubai Tennis Championships

British tennis legend Andy Murray has confirmed his participation at this month's Dubai Tennis...

M Sekar: Corpn Closes Down Six Shops For Not Paying Rent | Coimbatore News

Coimbatore: A team led by west zone assistant corporation commissioner M Sekar closed down...

NEET-PG 2023 registration window reopens on nbe.edu.in, MDS window to open tomorrow

NEW DELHI: In view of the requests made by candidates, the National Board...

More like this

AICTE Invites Application to Translate SWAYAM Online Courses

The All India Council for Technical Education (AICTE) has released a notice...

Andy Murray Grabs Wildcard To Compete At Dubai Tennis Championships

British tennis legend Andy Murray has confirmed his participation at this month's Dubai...

M Sekar: Corpn Closes Down Six Shops For Not Paying Rent | Coimbatore News

Coimbatore: A team led by west zone assistant corporation commissioner M Sekar closed...