Redirect & DB Tuning
Redis LRU Slug Cache Sizing & Cache-Miss Latency Penalty
Quantify why undersized Redis maxmemory drops 302 throughput from 6,200 req/s to under 500 req/s once cold misses hit PostgreSQL.
340 B/Slug · 2.4-4.1 ms Hit vs 38+ ms PG Miss · allkeys-lru
Calculating Exact Redis Slug Working Set Bytes
Each cached redirect key in Redis 7 consumes roughly 340 bytes including short slug string, destination URL, domain identifier, and jemalloc allocator metadata. Covering 35% of 1,000,000 active slugs requires only ~119 MB of pure key memory.
Enforcing allkeys-lru Over volatile-lru
Always configure --maxmemory-policy allkeys-lru when Redis serves both redirect lookups and rate-limit counters without uniform TTLs, ensuring cold slugs evict cleanly without OOM errors.
Measured Thresholds & Shortener Stack Parameters
| Cache State | Measured Throughput (2 vCPU) | p95 Redirect Latency |
|---|---|---|
| 99%+ Redis Slug Hit | 2,800 - 9,500 req/s | 2.4 - 4.1 ms |
| 85% Hit (Mild Eviction) | 1,450 req/s | 14.8 ms |
| < 50% Hit (PG Fallback Storm) | 480 req/s collapse | 38 - 95 ms |