
Deploy NATS
NATS 2.15 messaging server with JetStream, WebSocket and token auth.
Just deployed
/data
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
/datafor JetStream - A Railway TCP proxy for external client connections
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:
- 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.
Template Content