L i m i t i n g ? It is an approach to scalable and secure applications. Limiting the number of request to the application When you faced with HTTP 429 Error, there is implemented "rate limiting" approach. Picture resource: https://httpstatusdogs.com/429-too-many-requests
Managing and protecting server resources - Cpu, memory, network bandwidth. Controlling traffic due to increase demands suddenly. W h y I s I t I m p o r t a n t ?
Bucket S t r a t e g i e s - A l g o r i t h m s The choice of algorithm depends on the application’s specific requirements Sliding Window - Counter Based Dynamic Rate Limiter
t A token as processing request. Capacity of the bucket is defined. If the request came, token was leaving from the bucket until reaches refillment time.
t In distributed systems, we need to balance the refillment time and the request limit so that, there are no problems due to sudden resets. Solution is refill the bucket using refillment rate. Example: 5 request per 60 seconds Rate is 60/5=12 sec 10 requests in 6 seconds
t Requests are placed with FIFO (first in first out) queue structure and process regular intervals. If queue is full, there will not be accepted new request until process requests at the queue. Advantage over Token Bucket is the regular processing of requests at a fixed time interval.
w Allows limited number of request in fixed period of time. If exceeds, rejected until replenish the window/counter. In other words "N request per period" Example: 3 requests per 60 seconds
can lead to increased traffic. When the maximum request limit is reached at the beginning of the time window, it can wait for a long time to wait for the next time window. It depends on length of time window. F i x e d W i n d o w Problems can be encountered with Fixed Window
w V S T o k e n B u c k e t Refillment rate can be adjusted using refillment period and request limit. Token Bucket Refillment rate is constant. Fixed Window
d o w - L o g B a s e d Incoming request and it’s timestamp store in array with request period. If a new request is received, the requests in the last time period are checked. If the request limit is not reached, push it to the array.
d o w - C o u n t e r B a s e d The logic is time window divides into time segment. Sliding window moves when each time segment passed. Example; There is 60 seconds window and it divided three segments those are 20 seconds. Request Limit is 50.
C o u n t e r B a s e d The log-based method offers more detailed tracking and precise window control due to store timestamp. However this approach needs large data structures may be required and memory consumption is high. On the other hand; The counter-based method is more performant, but works with a slight loss of accuracy.
e L i m i t i n g Adaptive rate limiting adjusts the limit based on various factors such as client behavior, server load. In order to adjusted in real-time to optimize performance and prevent abuse
Chapter 4: Design A Rate Limiter Y o u m a y b e i n t e r e s t e d r e s o u r c e s API Rate Limiter System Design https://www.enjoyalgorithms.com/blog/design-api-rate-limiter Rate Limiting Kavramını ve Algoritmalarını Anlamak: https://mertmtn.blogspot.com/2022/09/rate-limiting-kavramn-ve-algoritmalarn.html Rate Limiting with Redis https://www.youtube.com/watch?v=YcmU24x4KyA&t=440s