Deploy Valkey HA
Valkey HA: 3-node Sentinel cluster with auto-failover.
valkey-2
Just deployed
/data
valkey-3
Just deployed
/data
valkey-1
Just deployed
/data
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-alpineimage (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
> Note: Direct connections do not follow failover. Use Sentinel-aware clients for production.
Connecting via code (Python example):
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:
- Connect via Sentinel and set a key:
master.set("test", "hello") - Stop
valkey-1(the primary) - Wait 5-10 seconds for Sentinel to detect failure and promote a replica
- Query via Sentinel:
master.get("test")— should still return"hello" - 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_PRIMARYpoints tovalkey-1.railway.internal - Check
VALKEY_PASSWORDis identical on all nodes - Verify Sentinel port 26379 is accessible between nodes (private network)
- Check logs for
+sdownor+odownmessages - DNS resolution: If you see "Can't resolve instance hostname", the primary's domain may not resolve yet. Node 1 uses
127.0.0.1to 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_memorybeing 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
masterauthmatchesrequirepasson all nodes - Check
replica-announce-ipis 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)}}onvalkey-1. Shared across all nodes. SetVALKEY_PASSWORDbefore 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.
Template Content
valkey-2
codestorm-official/valkey-havalkey-3
codestorm-official/valkey-havalkey-1
codestorm-official/valkey-ha