Interview › Databases & Caching
How would you use Redis for rate limiting?
Databases & Caching · Advanced level
Answer
For rate limiting, Redis commonly uses atomic counters with INCR and EXPIRE for fixed windows or sorted sets for sliding windows. Lua scripts help make multi-step limiter logic atomic.
Technical explanation
Rate limits can use INCR/EXPIRE or sorted sets, ideally through Lua for atomicity.
Distributed locks should use SET key value NX PX ttl with unique token and safe compare-and-delete release; they are better for efficiency than hard correctness.
Security baseline is private subnets, SG restrictions, TLS, AUTH/ACLs, secret rotation, and no public exposure.
Hands-on example
Rate limit example:
MULTI
INCR rl:tenant:42:minute:202606301015
EXPIRE rl:tenant:42:minute:202606301015 120
EXEC
Lock example:
SET lock:refresh:product:123 <uuid> NX PX 5000
Release only if GET lock value matches your uuid. Never DEL blindly.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- What is Amazon RDS, and what does it manage for you versus self-managed databases?
- What database engines does RDS support?
- What is the difference between RDS and Aurora?
- What is Multi-AZ in RDS, and how does automatic failover work?
- How long does an RDS Multi-AZ failover typically take, and what triggers it?
- What is the difference between Multi-AZ and a read replica?
- When would you use a read replica, and can it become a standalone database?
- Can a read replica be in a different region, and why would you do that?