Deploy & Host NATS | Railway

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

Dependencies for NATS Hosting

Deployment Dependencies

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:

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:

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.