System Design: Design a Token Bucket Rate Limiter
Explain how to structure a rate limiting system for a public API using a Redis-backed Token Bucket algorithm.
Technical Reference & Key Concepts
The Challenge: Design a Token Bucket Rate Limiter
You need to implement a rate limiter for an API endpoint that allows 100 requests per minute per user. You decide to use the Token Bucket algorithm backed by Redis.
Core questions to address:
- What keys and data structures will you store in Redis?
- How do you handle race conditions when updating the bucket under concurrent requests?
- How do you compute the token replenishment without running background cron jobs?