Persistence options, memory limits and security options that come with self-managed Redis- everything managed Redis offers on your VPS.
Why self-hosting Redis is the clear path to go
The cost of using managed Redis is incredible for what it provides: $15 per month or more for Redis instances with 256MB of RAM or more, while Redis itself is an extremely simple process that can run fine in a container alongside your app. Compared to other services that incur premiums for being managed, Redis has the smallest footprint of all.
Choose persistence according to the work being done
Redis has two options for persistence, and which is appropriate completely relies on what data is being stored:
Cache only (fragment caching, computed output): persistence OFF; restarting means simply clearing the cache
Queue/Session (Sidekiq, BullMQ, Celery): AOF with appendfsync everysec; maximum one second of data loss on a crash
Hybrid or "it would hurt to lose": RDB persistence plus AOF persistence; quick recovery with durability
queue/session-grade durability
appendonly yes
appendfsync everysec
save 900 1
# cache-grade
maxmemory 512mb
maxmemory-policy allkeys-lru
The memory configurations to protect you from outages
Unbounded Redis will grow till the kernel OOM-kills it, including your sessions. Set maxmemory (around 75% of the allocation for this container to have headroom for forks), select a sensible eviction policy, either allkeys-lru for caching which will make the memory constraints irrelevant or noeviction for queueing which will cause producer failures to notify you, not silently lose the job. Run two Redis instances if semantics differ.
Security: one rule above all
Do not expose port 6379 to the internet at any cost. Internet-facing Redis is hacked within hours via automatic scanners; one of the most commonly abused misconfigurations known. Leave Redis within the internal Docker network and accessible to your applications only; still set requirepass for security by obscurity; and rename FLUSHALL/FLUSHDB if you have multiple applications using the same database. As a Peon database service, there’s no public port until you make one yourself.
Operations and sizing
Watch used_memory vs maxmemory and evicted_keys (INFO memory); increasing evictions in the queue instance is a critical alarm signal
Allocation of 256 to 512 MB should suffice for most applications' caching/queueing requirements; Redis performance (100,000+ operations/sec even on minimal hardware) is unlikely to limit you
Backup for queue-class instances: snapshot the volume or perform BGSAVE to copy RDB/AOF files; no need for backups of purely caching instances
Upgrades: increment the pinned image version and redeploy; RDB/AOF files will preserve state through container redeploys
Top comments (0)