---
title: "Deploy Mongo HA"
description: "High-availability MongoDB replica set with an HAProxy entry point"
category: "Storage"
url: https://railway.com/deploy/mongo-ha
---

# Deploy Mongo HA

High-availability MongoDB replica set with an HAProxy entry point

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

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

- **Creator:** Paulo
- **Category:** Storage

## Template content

### MongoDB HA https://cms.railway.com/media/haproxy-icon.svg

- **Image:** ghcr.io/railwayapp-templates/mongo-ha/haproxy:3.2

### MongoDB-1 https://devicons.railway.app/i/mongodb.svg

- **Image:** ghcr.io/railwayapp-templates/mongo-ha/mongo:8.0

### MongoDB-2 https://devicons.railway.app/i/mongodb.svg

- **Image:** ghcr.io/railwayapp-templates/mongo-ha/mongo:8.0

### MongoDB-3 https://devicons.railway.app/i/mongodb.svg

- **Image:** ghcr.io/railwayapp-templates/mongo-ha/mongo:8.0

## Documentation

# Deploy and Host Mongo HA on Railway

Mongo HA is a high-availability MongoDB deployment: a three-member replica set with automatic failover behind an HAProxy entry point. If the primary goes down, the remaining members elect a new one and HAProxy routes connections to it within seconds, so your application keeps one connection string across failovers.

## About Hosting Mongo HA

Hosting Mongo HA gives you a MongoDB replica set whose elections run inside MongoDB itself, with no separate coordinator tier. Three data nodes (MongoDB-1, MongoDB-2, MongoDB-3) each keep a full copy of the data on their own volume; the HAProxy edge (MongoDB HA) probes every node's role and sends writes only to the current primary. Scaling adds replicas in pairs so the voter count stays odd (3, 5 or 7 members). Railway renders the cluster view, health, backups and scaling for the whole set.

## Common Use Cases

- **Production document stores** that cannot afford the downtime of a single-node MongoDB redeploy or host failure.
- **Applications with strict availability targets** where a failover must complete in seconds without a configuration change on the client.
- **Upgrading an existing Railway MongoDB service**: convert a standalone MongoDB to this cluster in place and keep its data.

## Dependencies for Mongo HA Hosting

None. Deploy the template and connect using the variables on the "MongoDB HA" (HAProxy) service.

### Deployment Dependencies

- MongoDB data node image: `ghcr.io/railwayapp-templates/mongo-ha/mongo` (the official `mongo` image plus a thin supervisor)
- HAProxy edge image: `ghcr.io/railwayapp-templates/mongo-ha/haproxy`

### Implementation Details

Each data node runs mongod as a replica set member with keyfile authentication. A supervisor guards the initiate-vs-join decision, adds new members through the primary, removes members that were deleted, and serves the `/health` and `/role` endpoints HAProxy routes by. Connection strings carry `directConnection=true`: without it a MongoDB driver learns the members' private hostnames from the primary and dials them directly, bypassing the edge. Use the `MONGO_URL` or `MONGO_PUBLIC_URL` from the "MongoDB HA" service; do not connect to individual MongoDB nodes.

## Why Deploy Mongo 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 scale it.

By deploying Mongo HA on Railway, you get a MongoDB replica set with automatic failover, a single stable connection string, per-node backups, and a cluster view in the dashboard, with no cluster administration on your side.


## 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
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

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