Deploy Redis HA (w/ Sentinel)
Redis replica set with Sentinel for automated failover
Redis Replica 1
Just deployed
/data
Redis Sentinel 1
Just deployed
Redis Sentinel 2
Just deployed
Redis Primary
Just deployed
/data
Redis Replica 2
Just deployed
/data
Redis Sentinel 3
Just deployed
Deploy and Host Redis HA (w/ Sentinel) on Railway
Redis HA with Sentinel is an open-source topology that provides automated failover for a single-writer Redis setup. Three Sentinel processes monitor a Redis primary and its replicas; if the primary becomes unavailable, a replica is promoted to master and the others are reconfigured automatically. Clients discover the current master via Sentinel, not a fixed hostname.
About Hosting Redis HA (w/ Sentinel)
This template deploys a production-ready, Sentinel-managed Redis stack on Railway. It provisions three Redis services (1 primary + 2 replicas), plus three Redis Sentinel services (port 26379) for monitoring and automated failover. All services communicate over Railway’s private network using internal DNS and shared credentials referenced via service variables. On failover, a replica is promoted to master and the returning old primary rejoins as a replica (no automatic “failback”). Clients should be Sentinel-aware to always route writes to the current master. Obs: TCP Proxy is already exposed on sentinels.
Common Use Cases
- Highly-available cache and session store for web backends and APIs
- Durable job/queue backends (e.g., BullMQ, RQ, Celery) with automated failover
- Rate limiting, token buckets, and ephemeral coordination using Redis primitives
Dependencies for Redis HA (w/ Sentinel) Hosting
- A Sentinel-aware client library (e.g., ioredis) to discover the current master
Deployment Dependencies
- Redis Sentinel (HA) docs: https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/
- ioredis Sentinel usage: https://github.com/luin/ioredis
Implementation Details
Client (Node + ioredis inside Railway):
import Redis from "ioredis";
const redis = new Redis({
sentinels: [
{ host: process.env.SENTINEL1_HOST, port: 26379 },
{ host: process.env.SENTINEL2_HOST, port: 26379 },
{ host: process.env.SENTINEL3_HOST, port: 26379 },
],
name: "myprimary", // Default name, can be set through env vars
family: 0, // Needed!
sentinelUsername: process.env.REDISUSER,
sentinelPassword: process.env.REDIS_PASSWORD, // Redis data password
username: process.env.REDISUSER,
password: process.env.REDIS_PASSWORD,
});
Quick verify commands:
- Quorum:
redis-cli -h -p 26379 SENTINEL ckquorum myprimary - Master:
redis-cli -h -p 26379 SENTINEL get-master-addr-by-name myprimary - Roles:
redis-cli -h -p 6379 -a INFO replication
Notes:
- Returning old primary becomes a replica; manual
SENTINEL failover myprimaryis needed if you want to “switch back.” - Prefer a specific replica for promotion with
--replica-priorityon start command (lower value = more preferred; 0 = never promote).
Why Deploy Redis HA (w/ Sentinel) on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Redis HA (w/ Sentinel) on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
Redis Replica 1
redis:8.4.0Redis Sentinel 1
redis:8.4.0Redis Sentinel 2
redis:8.4.0Redis Primary
redis:8.4.0Redis Replica 2
redis:8.4.0Redis Sentinel 3
redis:8.4.0