Memory Footprint per User and Limits
What You'll Learn
You'll learn how to calculate the exact memory cost per user or key for different rate limiting algorithms and use that to size your Redis deployment.
Why Memory Planning Matters
In a rate limiter service handling millions of users, even small per-user memory overhead multiplies quickly. If each user consumes 1 KB and you have 10 million active users, that's nearly 10 GB of RAM required. Understanding this math ensures your Redis cluster doesn't run out of memory or become prohibitively expensive.
Memory Footprint by Algorithm
Fixed Window Counter:
- 1 key per user → ~100 bytes (key + integer counter + metadata)
- Example:
user:123:minute→ 8-byte integer + ~50-byte key
Sliding Window Log:
- 1 sorted set per user storing timestamps → 50-200 bytes per request stored
- For 1000 requests/minute limit: ~200 KB per active user
- Much heavier but more accurate
Token Bucket:
- 1 hash per user storing tokens + last refill time → ~150 bytes
- Example:
{tokens: 100, last_refill: 1678901234}
Sliding Window Counter:
- Multiple keys per user (current + previous window) → ~200 bytes total
Capacity Planning Formula
Total Memory = (Users × Memory per User) + Overhead
Add 20-30% overhead for Redis internal structures. For 10M users with token bucket (150 bytes each):
(10,000,000 × 150) + 30% overhead ≈ 2 GB
Key Takeaway: Choose your algorithm knowing its memory cost—fixed window is lightest (~100 bytes/user), sliding log is heaviest (100KB+ for busy users)—then multiply by user count to properly provision Redis capacity.