---
title: "Deploy Valkey HA"
description: "Valkey HA: 3-node Sentinel cluster with auto-failover."
category: "Storage"
url: https://railway.com/deploy/valkey-ha
---

# Deploy Valkey HA

Valkey HA: 3-node Sentinel cluster with auto-failover.

**[Deploy Valkey HA on Railway](https://railway.com/template/valkey-ha)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/valkey-ha/manifest.json

- **Creator:** Rakit
- **Category:** Storage
- **Total deploys:** 1

## Template content

### valkey-2 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/valkey.svg

- **Source:** codestorm-official/valkey-ha

### valkey-3 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/valkey.svg

- **Source:** codestorm-official/valkey-ha

### valkey-1 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/valkey.svg

- **Source:** codestorm-official/valkey-ha

## Documentation

# Deploy and Host Valkey HA on Railway

A 3-node Valkey cluster with Sentinel-based automatic failover. Built for production workloads that need a Redis-compatible in-memory data store that survives node failures.

## About Hosting

Valkey HA deploys three nodes on Railway's private network, each running both a Valkey server and a Sentinel process. Sentinel monitors the primary, detects failures, and automatically promotes a replica to primary within seconds. All three nodes participate in Sentinel quorum (2 of 3) for failover decisions. Each node has its own persistent volume with AOF (append-only file) persistence, so data survives restarts and redeploys. Valkey is a Redis fork (BSD-licensed, Linux Foundation) with full Redis protocol compatibility — existing Redis clients, libraries, and commands work without modification. The Sentinel announce-ip mechanism ensures proper discovery over Railway's IPv6 private network. A single public TCP proxy provides external access to the current primary.

## Common Use Cases

- **Session storage** — shared sessions across multiple app instances with failover
- **Caching layer** — high-performance cache with automatic failover
- **Job queues** — reliable background job processing (Bull, Sidekiq, Celery)
- **Rate limiting** — distributed rate limiters that survive node failures
- **Pub/sub messaging** — real-time event distribution with failover
- **Leader election** — distributed locks and coordination primitives

## Dependencies for

- **Valkey 9.2.1** — official `valkey/valkey:9.2.1-alpine` image (24 MB)
- **Railway volumes** — one persistent volume per node at `/data` (3 volumes total)
- **Railway private networking** — IPv6 inter-service communication
- **Railway TCP proxy** — for external client access

### Implementation Details

Each node runs both Valkey server and a Sentinel process in a single container. Sentinel monitors the primary (initially `valkey-1`), detects failures after 5 seconds, and promotes a replica automatically. The quorum is 2 of 3 Sentinels. Replicas use `replica-announce-ip` and Sentinel uses `sentinel announce-ip` to ensure proper discovery over Railway's IPv6 private network.

**Default credentials:** Password is auto-generated via `${{secret(32)}}` on `valkey-1` and shared with all nodes. Set `VALKEY_PASSWORD` before deploy to control it.

**Sentinel connection (recommended for clients):**

Clients should connect through Sentinel for automatic failover:

```
sentinel://:password@valkey-1.railway.internal:26379,valkey-2.railway.internal:26379,valkey-3.railway.internal:26379/mymaster
```

**Direct connection (single node):**

Connect directly to the current primary:

```
redis://:password@valkey-1.railway.internal:6379
```

&gt; Note: Direct connections do not follow failover. Use Sentinel-aware clients for production.

**Connecting via code (Python example):**

```python
import redis
from redis.sentinel import Sentinel

sentinel = Sentinel(
    [("valkey-1.railway.internal", 26379),
     ("valkey-2.railway.internal", 26379),
     ("valkey-3.railway.internal", 26379)],
    socket_timeout=0.5,
    password=""
)

# Get a connection to the current primary
master = sentinel.master_for("mymaster", socket_timeout=0.5, password="")
master.set("key", "value")
print(master.get("key"))

# Get a connection to a replica (for reads)
replica = sentinel.slave_for("mymaster", socket_timeout=0.5, password="")
print(replica.get("key"))
```

**Testing failover:**

1. Connect via Sentinel and set a key: `master.set("test", "hello")`
2. Stop `valkey-1` (the primary)
3. Wait 5-10 seconds for Sentinel to detect failure and promote a replica
4. Query via Sentinel: `master.get("test")` — should still return `"hello"`
5. Restart `valkey-1` — it rejoins as a replica automatically

**Ports:**

| Port | Purpose | Exposure |
| --- | --- | --- |
| 6379 | Valkey (Redis protocol) | Private + TCP proxy for external |
| 26379 | Sentinel | Private (cluster only) |

**Volume:** One volume per node at `/data`. AOF + RDB snapshots enabled.

**Health check:** Valkey responds to `PING` on port 6379. Railway can use TCP check or `valkey-cli ping`.

## Comparison with Alternatives

| Feature | Valkey HA (this template) | Single Valkey | Redis HA (Railway managed) | KeyDB |
| --- | --- | --- | --- | --- |
| Failover | ✅ Sentinel (automatic) | ❌ | ✅ Sentinel (managed) | ✅ Active-replica |
| Setup complexity | ⚠️ 3 services | ✅ 1 service | ✅ 1-click conversion | ⚠️ 2+ services |
| Redis compatibility | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| License | ✅ BSD (Linux Foundation) | ✅ BSD | ✅ BSD (Redis 7.2) | ✅ BSD |
| Memory footprint | ⚠️ 3 nodes | ✅ Low | ⚠️ 3+ nodes | ⚠️ 2+ nodes |
| Client support | ✅ Sentinel-aware clients | ✅ All Redis clients | ✅ All Redis clients | ✅ All Redis clients |
| Self-hosted | ✅ | ✅ | ❌ Managed only | ✅ |
| Railway native HA | ❌ | ❌ | ✅ Built-in conversion | ❌ |

## Troubleshooting

### Sentinel not detecting primary

- Verify `VALKEY_PRIMARY` points to `valkey-1.railway.internal`
- Check `VALKEY_PASSWORD` is identical on all nodes
- Verify Sentinel port 26379 is accessible between nodes (private network)
- Check logs for `+sdown` or `+odown` messages
- **DNS resolution**: If you see "Can't resolve instance hostname", the primary's domain may not resolve yet. Node 1 uses `127.0.0.1` to avoid this. Peer nodes wait up to 60 seconds for DNS resolution before starting Sentinel.

### Memory overcommit warning

- Valkey logs a warning about `vm.overcommit_memory` being disabled
- This is a non-fatal warning — Valkey will still work
- Railway doesn't allow changing sysctl settings in containers
- For production, consider using a larger instance

### Replicas not syncing

- Verify `masterauth` matches `requirepass` on all nodes
- Check `replica-announce-ip` is set to the Railway private domain
- Verify network connectivity between nodes

### Split-brain after network partition

- Sentinel requires majority (2 of 3) to authorize failover
- In a 3-node setup, if 2 nodes are partitioned, failover will not occur
- This is by design — prevents data inconsistency

## Security Considerations

- **Password**: Auto-generated via `${{secret(32)}}` on `valkey-1`. Shared across all nodes. Set `VALKEY_PASSWORD` before deploy to control it.
- **Sentinel auth**: Sentinel uses the same password for `auth-pass`. Sentinel port (26379) is private only.
- **Network access**: Valkey (6379) accessible via TCP proxy for external clients. Consider keeping internal-only if clients run on Railway.
- **Protected mode**: Disabled (password is set, so protected mode is not needed).
- **Volume encryption**: Railway volumes are encrypted at rest.
- **No public Sentinel port**: Port 26379 is private only.

## Why Deploy Valkey HA 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 Valkey HA 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.

Three nodes with Sentinel quorum, AOF persistence, and automatic failover — no manual Sentinel configuration, no separate coordination service. Set the password and deploy.

## Similar templates

- [RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set](https://railway.com/deploy/rustfs-or-just-updated-s3-object-store-p) — S3-compatible object store, keys and public URL preset, volume kept
- [TimescaleDB](https://railway.com/deploy/timescaledb-railway-template) — Time-series analytics on PostgreSQL: fast, familiar, scalable.
- [Neo4j 2026.10 Community](https://railway.com/deploy/neo4j-202610-community) — Neo4j graph database with APOC, Browser, Bolt TCP proxy and a volume

Open this page in a browser: https://railway.com/deploy/valkey-ha
