Redis is fast – I'll cache in Postgres
12 hours ago
- #Redis
- #Caching
- #Postgres
- Comparison between using Postgres and Redis for caching in a simple HTTP server setup.
- Setup involves running Postgres or Redis on a k8s cluster with limited resources (2CPUs, 8GiB memory).
- Benchmarking includes get, set, and mixed operations with specific probabilities for cache hits/misses.
- Redis outperforms Postgres in all benchmarks (get, set, mixed) with better latency and lower resource usage.
- Postgres consistently maxes out CPU resources and uses more memory compared to Redis.
- Unlogged tables in Postgres improve write performance significantly but have minimal impact on reads.
- Despite Redis's superior performance, the author prefers Postgres for caching to avoid additional dependencies.
- Postgres can handle significant traffic (7425 requests per second) on modest hardware, suitable for most projects.
- The article suggests using an interface for cache to easily switch between Postgres and Redis if needed.