Design a rate limiter

Rate Limiter

Step 1 - Understand the problem and establish design scope

Questions to ask

Example requirements

Step 2 - Propose high-level design and get buy-in

CleanShot 2024-10-16 at 13.33.25@2x.png

How to implement the rate limiter

Algorithms

Token bucket

Leaking bucket algorithm

Fixed window counter

Sliding window log

Sliding window counter

High level architecture

Step 3 - Design deep dive

CleanShot 2024-10-16 at 14.42.17@2x.png

Rate limiting rules

domain: auth
descriptors:
	- key: auth_type
	  Value: login
	  rate_limit:
		  unit: minute
		  requests_per_unit: 5

Exceeding the rate limit

Distributed environment

Race condition

Synchronisation issue

Performance optimisation

Monitory

Step 4 - Wrap up

Additional discussions

Hard vs soft rate limiting

Rate limiting on different HTTP layer

Design client to avoid being rate limited