1. Algorithm
The token bucket refills at a steady rate and lets each request spend a token, allowing short bursts up to the bucket size.
algorithm: token-bucketTyporithm · medium
Step 1 of 8 · intro card
Reliability
Rate limiting caps how many requests a client may make in a window. Token bucket, leaky bucket, and sliding window are the common algorithms; a distributed Redis counter enforces the limit across servers, and exceeding it returns 429 with Retry-After.
Rate limiting protects a service from abuse and overload by capping requests over a time window. The token bucket, leaky bucket, and sliding window are the three algorithms you will see most often.
Limits are keyed by scope: per-user, per-IP, or global. Because requests hit many servers, a shared counter in a store like Redis enforces the same quota everywhere instead of each instance counting on its own.
When a client exceeds its limit, the service responds with HTTP 429 Too Many Requests and a Retry-After header so well-behaved clients back off. A token bucket lets a short burst through, then throttles to the steady refill rate.
Token bucket, leaky bucket, sliding window are the common algorithms.
Scope the limit per-user, per-IP, or global.
Exceeding the limit returns 429 with Retry-After.
rate_limit:
algorithm: token-bucket
scope: per-user-or-ip
store: redis-counter
response: 429-retry-after
burst: allow-then-throttleConnect each part of the code to the concept before you type.
The token bucket refills at a steady rate and lets each request spend a token, allowing short bursts up to the bucket size.
algorithm: token-bucketLimits can apply per-user, per-IP, or globally — picking the right key decides who shares a quota.
scope: per-user-or-ipA shared counter in Redis enforces the limit across all servers, not just one process.
store: redis-counterExceeding the limit returns HTTP 429 Too Many Requests with a Retry-After header telling the client when to try again.
response: 429-retry-afterA bucket absorbs a short burst, then throttles steady traffic to the refill rate.
burst: allow-then-throttleRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.