---
title: "Deploy EMQX HA"
description: "EMQX HA: 3-node MQTT cluster with auto-discovery and failover."
category: "Queues"
url: https://railway.com/deploy/emqx-ha
---

# Deploy EMQX HA

EMQX HA: 3-node MQTT cluster with auto-discovery and failover.

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

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

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

## Template content

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

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

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

- **Source:** codestorm-official/emqx-ha
- **Public domain:** Yes

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

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

## Documentation

# Deploy and Host EMQX HA on Railway

A 3-node EMQX MQTT cluster with automatic failover and built-in clustering. Built for production IoT and messaging workloads that need fault-tolerant MQTT brokering.

## About Hosting

EMQX HA deploys three core nodes on Railway's private IPv6 network. EMQX uses Erlang clustering for high availability — nodes form a cluster automatically using static discovery. All three nodes are core nodes (no replicant nodes needed for this size). The cluster handles message routing, session management, and subscription state across all nodes. Each node has its own persistent volume for data and configuration. MQTT clients can connect to any node, and messages are routed within the cluster. The built-in dashboard on port 18083 provides cluster monitoring, client management, and rule configuration. EMQX supports MQTT 3.1, 3.1.1, and 5.0 protocols, plus WebSocket and HTTP APIs. IPv6 is enabled for Erlang distribution and all listeners.

## Common Use Cases

- **IoT device management** — connect thousands of IoT devices via MQTT
- **Smart home automation** — MQTT broker for Home Assistant, Zigbee, Z-Wave
- **Telemetry collection** — sensor data ingestion and routing
- **Real-time messaging** — pub/sub messaging for mobile and web apps
- **Industrial IoT** — factory floor device communication
- **Connected vehicles** — telemetry and command routing

## Dependencies for

- **EMQX 5.8.9** — official `emqx/emqx:5.8.9` image (Apache 2.0). Pinned to the last Apache-2.0 line on purpose: EMQX 5.9+ ships a Community License that only permits single-node use, while clustering requires a commercial license — 5.8.x keeps multi-node HA legally unrestricted.
- **Railway volumes** — one persistent volume per node at `/opt/emqx/data` (3 volumes total)
- **Railway private networking** — IPv6 inter-service communication
- **Railway TCP proxy** — for external MQTT client access

### Implementation Details

Each node runs EMQX in core mode. Static discovery is used — all three nodes are listed in the seed list. Erlang distribution uses IPv6 (`inet6_tcp`) for Railway's private network. The RPC channel listens on `::` (IPv6). All MQTT listeners (1883, 8883, 8083, 8084) bind to `[::]` for dual-stack (IPv4 + IPv6) support.

**Default credentials:** Dashboard username is `admin`. Password is auto-generated via `${{secret(16)}}` on `emqx-1` and shared with all nodes. Set `EMQX_DASHBOARD_PASSWORD` before deploy to control it.

**Accessing the dashboard:**

1. Open the public domain assigned to `emqx-1` (port 18083)
2. Log in with username `admin` and the generated password
3. Navigate to **Cluster** → **Overview** to see all 3 nodes
4. Navigate to **Clients** to see connected MQTT clients

**Connecting MQTT clients:**

Internal (private network, no auth by default):
```
mqtt://emqx-1.railway.internal:1883
```

External (TCP proxy, with auth):
```
mqtt://<tcp-proxy-host>:<tcp-proxy-port>
```

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

```python
import paho.mqtt.client as mqtt

client = mqtt.Client()
client.username_pw_set("admin", "<password>")  # if auth enabled
client.connect("emqx-1.railway.internal", 1883, 60)

# Publish
client.publish("test/topic", "Hello from Railway")

# Subscribe
def on_message(client, userdata, msg):
    print(f"{msg.topic}: {msg.payload.decode()}")

client.on_message = on_message
client.subscribe("test/topic")
client.loop_forever()
```

**Connecting via code (Node.js example):**

```javascript
const mqtt = require('mqtt');
const client = mqtt.connect('mqtt://emqx-1.railway.internal:1883');

client.on('connect', () => {
    client.subscribe('test/topic');
    client.publish('test/topic', 'Hello from Railway');
});

client.on('message', (topic, message) => {
    console.log(`${topic}: ${message.toString()}`);
});
```

**Verifying cluster status:**

```bash
# From any node's shell
emqx ctl cluster status
```

Expected output: 3 running nodes, 0 stopped nodes.

**Testing failover:**

1. Connect an MQTT client to `emqx-1`
2. Publish messages to a topic
3. Stop `emqx-1`
4. Client should reconnect to `emqx-2` or `emqx-3` automatically
5. Messages published during failover are queued (if using QoS 1/2)
6. Restart `emqx-1` — it rejoins the cluster

**Ports:**

| Port | Purpose | Exposure |
| --- | --- | --- |
| 1883 | MQTT (TCP) | Private + TCP proxy for external |
| 8883 | MQTT (SSL/TLS) | Private + TCP proxy for external |
| 8083 | WebSocket | Private + TCP proxy for external |
| 8084 | WebSocket (SSL/TLS) | Private + TCP proxy for external |
| 18083 | Dashboard & HTTP API | Public (via Railway domain) |
| 4370 | Erlang distribution | Private (cluster only) |
| 5369/5370 | Cluster RPC | Private (cluster only) |

**Volume:** One volume per node at `/opt/emqx/data`.

**Health check:** `emqx ctl status` or HTTP `GET /api/v5/status` on port 18083.

## Comparison with Alternatives

| Feature | EMQX HA (this template) | Single EMQX | Mosquitto | HiveMQ |
| --- | --- | --- | --- | --- |
| Clustering | ✅ Native (Erlang) | ❌ | ❌ | ✅ (Enterprise) |
| MQTT protocol | ✅ 3.1, 3.1.1, 5.0 | ✅ 3.1, 3.1.1, 5.0 | ✅ 3.1, 3.1.1, 5.0 | ✅ 3.1, 3.1.1, 5.0 |
| WebSocket | ✅ Built-in | ✅ Built-in | ⚠️ Plugin | ✅ Built-in |
| HTTP API | ✅ Built-in | ✅ Built-in | ❌ | ✅ Built-in |
| Dashboard | ✅ Built-in | ✅ Built-in | ❌ | ✅ Built-in |
| Memory footprint | ⚠️ 3 Erlang VMs | ✅ Low | ✅ Very low | ⚠️ Java (high) |
| Cost (self-hosted) | ⚠️ 3 services | ✅ 1 service | ✅ 1 service | ❌ Enterprise |
| License | ✅ Apache 2.0 (CE) | ✅ Apache 2.0 (CE) | ✅ EPL/EDL | ❌ Proprietary |

## Security Considerations

- **Dashboard password**: Auto-generated via `${{secret(16)}}` on `emqx-1`. Shared across all nodes. Set `EMQX_DASHBOARD_PASSWORD` before deploy to control it.
- **Default auth**: EMQX has built-in authentication (file-based by default). Configure additional auth (JWT, LDAP, etc.) via dashboard.
- **Network access**: MQTT (1883) accessible via TCP proxy for external clients. WebSocket (8083) accessible via TCP proxy. Dashboard (18083) is public.
- **Cluster ports**: 4370, 5369, 5370 are private only — never expose publicly.
- **SSL/TLS**: Port 8883 (MQTT SSL) and 8084 (WSS) available. Configure certificates via dashboard or config.
- **Volume encryption**: Railway volumes are encrypted at rest.

## Why Deploy EMQX 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 EMQX 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 EMQX nodes with Erlang clustering, automatic failover, and a built-in dashboard — no separate coordination service, no manual cluster configuration. Set the password and deploy.

## Similar templates

- [Celery | Web, Worker and Scheduler as Three Services](https://railway.com/deploy/celery-or-web-work-1) — Web, worker and scheduler wired up: Celery on Redis, outcomes in Postgres.
- [smoothmq](https://railway.com/deploy/AJv-64) — A drop-in replacement for AWS SQS
- [Kafka UI](https://railway.com/deploy/kafka-ui) — Kafbat UI — Open-source web UI to monitor and manage Apache Kafka clusters

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