Deploy Redis

Railway offers two Redis deployment options to accommodate different needs: a Standalone Instance and a High Availability (HA) Cluster.

  • Standalone Instance - a single Redis server that is easy to manage; ideal for development environments, smaller projects, or services that are less sensitive to disruption.

  • High Availability (HA) Cluster - intended for production workloads where uptime is critical. It consists of three Redis nodes in replication mode, complemented by three Sentinel services for automatic failover.

Standalone Redis

Let's talk about how to deploy, connect, and manage the standalone instance.

Deploy

You can deploy a standalone Redis database via the CMD + K menu or by clicking the + New button on the Project Canvas.

GIF of the Adding Database

You can also deploy it via the template from the template marketplace.

Deployed Service

Upon deployment, you will have a standalone Redis service running in your project, deployed from the bitnami/redis Docker image.

Connect

Connect to the Redis server from another service in your project by referencing the environment variables made available in the Redis service:

  • REDISHOST
  • REDISUSER
  • REDISPORT
  • REDISPASSWORD
  • REDIS_URL

Connecting Externally

It is possible to connect to Redis externally (from outside of the project in which it is deployed), by using the TCP Proxy which is enabled by default.

Keep in mind that you will be billed for Network Egress when using the TCP Proxy.

Modify the Deployment

Since the deployed container is pulled from the bitnami Redis image in Docker Hub, you can modify the deployment based on the instructions in Docker Hub.

High Availability Redis Cluster

We'll cover how to deploy, connect, and manage the High Availability (HA) Redis Cluster in this section.

Deploy

You can deploy a HA Redis Cluster via the template in the marketplace.

Redis HA in the marketplace

Deployed Services

Upon deployment, you will have a cluster of 3 Redis nodes deployed from the bitnami/redis image, running in replication mode.

Additionally, 3 Sentinel nodes will be deployed from the bitnami/redis-sentinel image to manage failover.

Multi-region Deployment

By default, each node is deployed to a different region (US West, US East, and EU West) for fault tolerance.

Since region selection is a Pro-only feature, this only applies to Pro users. If you deploy this template as a Hobby user, all nodes will deploy to US West.

Connect

To connect to the Redis cluster, you should connect via the Sentinel services using the environment variables available in the Sentinel services.

Sentinel variables

The exact method to configure your client will depend on the client library you are using. As an example, a Node.js server using ioredis can be found here here.

Connecting Externally

It is possible to connect to the Redis cluster externally (from outside of the project in which it is deployed) by using the TCP Proxy.

Keep in mind that you will be billed for Network Egress when using the TCP Proxy.

Modify the Deployment

Since the deployed containers are based on the bitnami/redis and bitnami/redis-sentinel images, you can refer to the documentation for each to understand how to customize them:

Backup and Monitoring

Especially for production environments, performing backups and monitoring the health of your data is essential. Consider adding:

  • Backup solutions: Automate regular backups to ensure data recovery in case of failure.

  • Observability: Implement monitoring for insights into performance and health of your Redis cluster. You can integrate a Redis exporter for Prometheus, although we do not provide a specific template at this time.

Additional Resources

While these templates are available for your convenience, they are considered unmanaged, meaning you have total control over their configuration and maintenance.

We strongly encourage you to refer to the source documentation to gain deeper understanding of their functionality and how to use them effectively. Here are some links to help you get started:


Edit this file on GitHub