Back to results for “Rate Limiting with Redis”
Redis › Rate Limiting with Redis

How would you design a tiered rate limiting system that applies different limits based on a user's subscription plan?

Advanced

Answer

You would store each user's specific limit, either directly with their rate limit key or looked up separately based on their plan, and pass that appropriate limit value into your rate limiting logic, allowing free tier users to have a lower limit while premium users receive a higher limit, all using the same underlying rate limiting mechanism.
-- Look up the user's specific limit based on their plan
local userLimit = plan == 'premium' and 1000 or 100
local count = redis.call('incr', KEYS[1])
return count <= userLimit
Real-world example An API provider offers free tier customers one hundred requests per hour while premium customers receive one thousand, using the same underlying Redis rate limiting logic but with a different limit value applied based on each customer's specific plan.

Common follow-ups: How do you handle a user who upgrades their plan mid billing cycle?;Should different endpoints within the same application have different rate limits?