Rate limiting is an essential technique used in software systems to control the rate of incoming requests. It helps to prevent the overloading of servers by limiting the number of requests that can be made in a given time frame. It helps to prevent a high volume of requests from overwhelming a server or API
Avoid resource starvation due to a Denial of Service (DoS) attack.
Ensure that servers are not overburdened. Using a rate restriction per user
ensures fair and reasonable use without harming other users.
Control the flow of information, for example, prevent a single worker from
accumulating a backlog of unprocessed items while other workers are idle.
A rate limiter should generally be implemented on the server side rather than on the client side. This is because of the following points:
Here are 2 algorithms that can be used for the Rate limiter
Token Bucket
The Token Bucket algorithm is another widely used approach for rate limiting that provides flexibility in handling burst traffic.
Sliding Window Algorithm
The Sliding Window algorithm is a time-based approach that tracks the number of requests made by a user within a fixed time window. a sliding time window that moves forward in fixed intervals, tracking the requests made by each user within the defined time span.
Considering a rate limiter design using the Sliding Window algorithm, here are some essential APIs:
These APIs provide the necessary functionalities to manage, monitor, and adjust rate limits using the Sliding Window algorithm. They ensure flexibility and control over rate-limiting parameters while offering insights into user activity.
For the tables required in this design, refer to the class diagram, the list of classes is not exhaustive but this is a good number of tables to start with.
Data Partitioning:
Sharding:
Replication:
Load Balancing:
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?