---
title: "Deploy NATS"
description: "NATS 2.15 messaging server with JetStream, WebSocket and token auth."
category: "Queues"
url: https://railway.com/deploy/nats-2
---

# Deploy NATS

NATS 2.15 messaging server with JetStream, WebSocket and token auth.

**[Deploy NATS on Railway](https://railway.com/template/nats-2)**

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

- **Creator:** Agaz Self-Host
- **Category:** Queues

## Template content

### nats https://github.com/nats-io.png

- **Image:** nats:2.15.0-alpine
- **Start command:** `sh -c 'printf "%s\n" "$NATS_CONFIG" > /tmp/nats.conf && exec nats-server -c /tmp/nats.conf'`
- **Health check:** /healthz
- **Public domain:** Yes

## Documentation

# Deploy and Host NATS on Railway

NATS is a high-performance messaging system for services, devices and browsers. It provides publish/subscribe, request/reply and, with JetStream, persistent streams, key-value and object stores. Client libraries exist for Go, Rust, Node.js, Python, Java, .NET, C and more, and browsers connect over WebSocket. The server is a single small binary.

## About Hosting NATS

This template deploys NATS Server v2.15.0 with JetStream enabled and stored on a Railway volume, so streams survive restarts. Clients authenticate with a generated token. Services on Railway connect over the private network on port 4222, external clients use the Railway TCP proxy, and browsers or serverless clients use WebSocket on the public HTTPS domain. The monitoring endpoint answers the health check privately. The config lives in the `NATS_CONFIG` variable, so accounts, users or limits can be changed without a custom image. Watch JetStream disk use on the Hobby plan.

## Common Use Cases

- Event streaming and work queues between microservices with JetStream
- Real-time messaging to browsers and mobile apps over WebSocket
- Lightweight request/reply RPC between services on Railway

## Dependencies for NATS Hosting

- `nats:2.15.0-alpine` (official image)
- A Railway volume at `/data` for JetStream
- A Railway TCP proxy for external client connections

### Deployment Dependencies

- [NATS documentation](https://docs.nats.io/)
- [NATS v2.15.0 release](https://github.com/nats-io/nats-server/releases/tag/v2.15.0)
- [NATS client libraries](https://nats.io/download/)
- [Railway TCP proxy](https://docs.railway.com/reference/tcp-proxy)

### Implementation Details

| Service | Image | Networking | Storage |
| --- | --- | --- | --- |
| nats | `nats:2.15.0-alpine` | private 4222; TCP proxy to 4222; public WebSocket on 8080 | volume at `/data` |

Connection URLs:

```env
NATS_URL=${{nats.NATS_URL}}                          # nats://@nats.railway.internal:4222
NATS_WEBSOCKET_URL=${{nats.NATS_WEBSOCKET_URL}}      # wss://, pass the token in the client options
```

External: `nats://@:`.

| Variable | Default | Purpose |
| --- | --- | --- |
| `NATS_TOKEN` | generated | Client authentication token |
| `NATS_JETSTREAM_MAX_FILE` | `4G` | JetStream disk limit; keep below your volume size |
| `NATS_CONFIG` | server config | Full `nats-server.conf`, reads `$NATS_*` variables |

Notes:

- The TCP proxy carries plain NATS without TLS; prefer WebSocket over HTTPS or the private network for sensitive data, or add TLS in `NATS_CONFIG`.
- Lame duck mode (30 s) and a 35 s draining window let clients move off cleanly during redeploys.

This is a community-maintained deployment package and does not imply affiliation with or endorsement by the NATS project or its maintainers.

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


## Similar templates

- [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
- [NATS + JetStream](https://railway.com/deploy/nats-jetstream) — An open source messaging system that promises at-most-once delivery.

Open this page in a browser: https://railway.com/deploy/nats-2
