news.volyx.in

Visualizing algorithms for rate limiting (smudge.ai)

390 points by seabass · 820 days ago · 49 comments on HN

Article summary

The article discusses the importance of rate limiting in controlling traffic to a service, and explores three common algorithms: fixed windows, sliding windows, and token buckets. Each algorithm has its pros and cons, and the choice of algorithm depends on the specific use case. The article also highlights the need to consider additional factors such as handling time zones, persisting rate limiter data, and surfacing useful rate limiting errors. The author provides examples of how these algorithms are used in real-world applications, including GitHub and Stripe.

Main themes

  • Rate limiting algorithms
  • Traffic control
  • Service protection
  • Algorithm comparison
  • Real-world applications
  • System capacity

What commenters say

  • Rate limits do not necessarily protect against backend capacity issues, and should be considered as a policy enforcement mechanism rather than a protection against overuse of resources.
  • Adding jitter to rate limit expiration times can help prevent large groups of rate limits from expiring at the same time, reducing the impact of burst traffic.
  • Fair queuing can be an effective approach to prevent DoS attempts from degrading service in a multitenant environment, by giving each client their own queue and servicing requests in a round-robin manner.
  • Token bucket algorithms can be used to handle priority and cost-based rate limiting, by assigning tokens to each queue and resetting them based on the cost of the request.
  • Some argue that rate limiting is not sufficient to prevent system overload, and that additional measures such as traffic prioritization and queueing are necessary to ensure system stability.
  • Others suggest that rate limiting can be effective in preventing system overload, but that it requires careful consideration of factors such as time zones, persisting rate limiter data, and surfacing useful rate limiting errors.
  • There is a trade-off between the benefits of multitenancy and the need to provision for maximum rates on all clients simultaneously, and some argue that fair scheduling can help mitigate this issue.
  • Some propose using alternative approaches, such as requiring clients to solve puzzles to make requests, as a way to prevent Sybil attacks and enforce rate limits.