NATS and JetStream on dedicated servers

NATS is a single small binary that connects services with publish-subscribe, request-reply and, with JetStream, persistent streams. It starts in milliseconds and uses very little memory.

What does NATS do?

It routes messages by subject between any number of clients. Core NATS is fire-and-forget publish-subscribe and request-reply with very low latency. JetStream, built into the same server, adds persistence: streams store messages on disk, consumers track what each reader has seen, and replicated streams survive node failures. On top of streams sit a key-value store and an object store. Clients exist for most languages.

How do I install and configure it?

Download the release binary or use the official package, then write one configuration file. A three-node cluster member with JetStream:

# /etc/nats/server.conf
server_name: nats-fra-1
listen: 0.0.0.0:4222
http: 127.0.0.1:8222
jetstream {
  store_dir: /var/lib/nats
  max_file_store: 800G
  max_memory_store: 8G
}
cluster {
  name: core
  listen: 10.40.0.1:6222
  routes: [ nats://10.40.0.2:6222, nats://10.40.0.3:6222 ]
}

Run it under systemd with nats-server -c /etc/nats/server.conf, as an unprivileged user that owns the store directory.

Which ports does it use?

PortPurposeExposure
4222ClientsApplications, with TLS and authentication
6222Cluster routesOther cluster members, over WireGuard
8222Monitoring HTTPLocalhost or monitoring host only
7422Leaf node connectionsRemote leaf nodes, with TLS

How do I secure clients?

With accounts and per-user permissions at minimum, and with the decentralised JWT model for larger setups, where operators and accounts are signed and users carry their own credentials. Each account is an isolated subject namespace, so tenants or teams never see each other's traffic unless you export and import subjects deliberately. Enable TLS on port 4222 whenever clients connect across the internet.

How do streams and consumers work?

A stream captures subjects into storage with limits on age, size or message count. Consumers read from it, either pushing to a subject or pulled in batches by workers, and track acknowledgements. Replication is per stream: R1 for disposable data, R3 for anything important.

nats stream add ORDERS --subjects "orders.>" --storage file --replicas 3 --retention limits --max-age 14d --defaults
nats consumer add ORDERS billing --pull --ack explicit --deliver all --max-deliver 5 --defaults
nats kv add sessions --replicas 3 --ttl 30m

How do leaf nodes help?

A leaf node is a NATS server that connects to a cluster as a single client and extends it to another location: an office, a factory, a second data centre or an edge server. Local clients talk to the leaf with local latency, and only the subjects that need to cross travel over the link. This suits a main cluster in Gravelines with leaves in Singapore or Toronto.

How much hardware does NATS need?

Very little for core NATS: a node handles millions of small messages a second on a few cores with a few hundred megabytes of memory. JetStream adds disk work, since R3 streams write each message on three nodes and acknowledge after a majority stores it; NVMe drives keep that fast. Plan disk for retention: a stream receiving 5,000 messages a second of 1 KB each, kept 14 days, needs about 6 TB per replica.

UseMachine
Core NATS and small streams, three nodes3 x ESSENTIAL-1
JetStream with moderate retention3 x ESSENTIAL-4
Long retention on large drives3 x STORAGE-2 2024

ESSENTIAL-1 costs $38.40 a month on a 3, 12 or 24 month term, which makes a three-node cluster inexpensive. The RabbitMQ servers and Apache Kafka clusters pages cover other messaging systems.

Machines for NATS clusters

Lowest monthly price of each model across its data centres; the model page shows the price in every location.

ModelProcessorCoresMemoryDrivesPortPer month
ESSENTIAL-1Intel Xeon-E 2386G632 GB2x 512 GB SSD NVMe1 Gbps unmetered$38.40
ESSENTIAL-2Intel Xeon-E 2388G832 GB2x 512 GB SSD NVMe1 Gbps unmetered$43.20
ESSENTIAL-SAMD Ryzen 7 9700X864 GB2x 512 GB SSD NVMe1 Gbps unmetered$46.20
ESSENTIAL-4AMD EPYC 73131664 GB2x 960 GB SSD NVMe1 Gbps unmetered$106.20
STORAGE-1AMD Ryzen 7 Pro 3700832 GB2x 480 GB SSD SATA + 4x 14 TB HDD SAS1 Gbps unmetered$109.80
STORAGE-2 2024AMD EPYC 4344P832 GB2x 960 GB SSD NVMe + 2x 22 TB HDD SAS3 Gbps unmetered$187.80

Three small nodes form a resilient cluster; add drives when JetStream retention grows.

See all servers and prices

Related pages

RabbitMQ servers

Run RabbitMQ brokers on bare metal: quorum queues and streams, the ports a node uses, memory and disk alarms, three-node clusters over WireGuard.

Read more

Apache Kafka clusters

Run Apache Kafka in KRaft mode on bare metal: controllers and brokers, log directories on many drives, replication settings, page cache and retention sizing.

Read more

Apache Pulsar servers

Run Apache Pulsar on bare metal: stateless brokers, BookKeeper bookies with separate journal and ledger disks, metadata stores, ports and tiered storage.

Read more

Company VPN gateways

Small, efficient machines for WireGuard and IPsec gateways that connect staff, offices and servers privately.

Read more

Questions and answers

What is JetStream in NATS?

The persistence layer built into the NATS server. It stores messages in streams, tracks consumers and replicates data across nodes.

Which ports does NATS use?

4222 for clients, 6222 for cluster routes, 8222 for monitoring and 7422 for leaf node connections.

How many replicas should a JetStream stream have?

Use three replicas for important data so the stream survives one node failure; one replica suits disposable data.

Is a NATS server light on RAM?

Core NATS uses a few hundred megabytes even under heavy load. JetStream adds disk work, so plan NVMe capacity for retention.

What is a NATS leaf node?

A NATS server that joins a cluster as one client to extend it to another location, keeping local traffic local.