---
title: "Deploy Redis HA (w/ Sentinel)"
description: "One-click Redis replica set with Sentinel for automated failover"
category: "Storage"
url: https://railway.com/deploy/redis-ha-w-sentinel
---

# Deploy Redis HA (w/ Sentinel)

One-click Redis replica set with Sentinel for automated failover

**[Deploy Redis HA (w/ Sentinel) on Railway](https://railway.com/template/redis-ha-w-sentinel)**

- **Creator:** Medim's Projects
- **Category:** Storage
- **Total deploys:** 3

## Template content

### Redis Replica 1 https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --masterauth $MASTER_PASS --replicaof $MASTER_HOST $MASTER_PORT --appendonly yes --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH" --protected-mode no`

### Redis Sentinel 1 https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c 'printf "%s\n" \ "protected-mode no" \ "port ${SENTINEL_PORT:-26379}" \ "" \ "sentinel monitor ${REDIS_PRIMARY_NAME} ${MASTER_HOST} ${MASTER_PORT} ${SENTINEL_QUORUM}" \ "sentinel auth-pass ${REDIS_PRIMARY_NAME} ${MASTER_PASS}" \ "sentinel down-after-milliseconds ${REDIS_PRIMARY_NAME} ${REDIS_DOWN_AFTER_MS}" \ "sentinel failover-timeout ${REDIS_PRIMARY_NAME} ${REDIS_FAILOVER_TIMEOUT_MS}" \ "sentinel parallel-syncs ${REDIS_PRIMARY_NAME} ${SENTINEL_PARALLEL_SYNCS}" \ "sentinel resolve-hostnames yes" \ "sentinel announce-hostnames yes" \ > /tmp/sentinel.conf && exec docker-entrypoint.sh redis-server /tmp/sentinel.conf --sentinel'`

### Redis Sentinel 2 https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c 'printf "%s\n" \ "protected-mode no" \ "port ${SENTINEL_PORT:-26379}" \ "" \ "sentinel monitor ${REDIS_PRIMARY_NAME} ${MASTER_HOST} ${MASTER_PORT} ${SENTINEL_QUORUM}" \ "sentinel auth-pass ${REDIS_PRIMARY_NAME} ${MASTER_PASS}" \ "sentinel down-after-milliseconds ${REDIS_PRIMARY_NAME} ${REDIS_DOWN_AFTER_MS}" \ "sentinel failover-timeout ${REDIS_PRIMARY_NAME} ${REDIS_FAILOVER_TIMEOUT_MS}" \ "sentinel parallel-syncs ${REDIS_PRIMARY_NAME} ${SENTINEL_PARALLEL_SYNCS}" \ "sentinel resolve-hostnames yes" \ "sentinel announce-hostnames yes" \ > /tmp/sentinel.conf && exec docker-entrypoint.sh redis-server /tmp/sentinel.conf --sentinel'`

### Redis Primary https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH"`

### Redis Replica 2 https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --masterauth $MASTER_PASS --replicaof $MASTER_HOST $MASTER_PORT --appendonly yes --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH" --protected-mode no`

### Redis Sentinel 3 https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.4.0
- **Start command:** `/bin/sh -c 'printf "%s\n" \ "protected-mode no" \ "port ${SENTINEL_PORT:-26379}" \ "" \ "sentinel monitor ${REDIS_PRIMARY_NAME} ${MASTER_HOST} ${MASTER_PORT} ${SENTINEL_QUORUM}" \ "sentinel auth-pass ${REDIS_PRIMARY_NAME} ${MASTER_PASS}" \ "sentinel down-after-milliseconds ${REDIS_PRIMARY_NAME} ${REDIS_DOWN_AFTER_MS}" \ "sentinel failover-timeout ${REDIS_PRIMARY_NAME} ${REDIS_FAILOVER_TIMEOUT_MS}" \ "sentinel parallel-syncs ${REDIS_PRIMARY_NAME} ${SENTINEL_PARALLEL_SYNCS}" \ "sentinel resolve-hostnames yes" \ "sentinel announce-hostnames yes" \ > /tmp/sentinel.conf && exec docker-entrypoint.sh redis-server /tmp/sentinel.conf --sentinel'`

## Documentation

# 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):
```js
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 sentinelhostnamehere -a passwordhere -p 26379 SENTINEL ckquorum myprimary`
- Master: `redis-cli -h masterhostnamehere -a passwordhere -p 26379 SENTINEL get-master-addr-by-name myprimary`
- Roles: `redis-cli -h hostnamehere -a passwordhere -p 6379 -a  INFO replication`

Notes:
- Returning old primary becomes a replica; manual `SENTINEL failover myprimary` is needed if you want to “switch back.”
- Prefer a specific replica for promotion with `--replica-priority` on 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.

## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [Postgres Backup to Cloudflare R2 (S3-Compatible)](https://railway.com/deploy/postgres-to-r2-backup) — Automated PostgreSQL backups to S3-compatible storage with encryption

Open this page in a browser: https://railway.com/deploy/redis-ha-w-sentinel
