ScriptsApr 10, 2026·3 min read

NATS — Cloud Native High-Performance Messaging System

NATS is a simple, secure, and high-performance messaging system for cloud-native applications, IoT, and microservices. Pub/sub, request/reply, and streaming with JetStream.

TL;DR
NATS provides pub/sub, request/reply, and persistent streaming for cloud-native microservices.
§01

What it is

NATS is a simple, secure, and high-performance messaging system designed for cloud-native applications, IoT, and microservices architectures. It supports publish/subscribe, request/reply, and persistent streaming via JetStream. NATS is written in Go and operates as a single binary with zero external dependencies.

NATS is for backend engineers and platform teams who need lightweight, high-throughput messaging between microservices without the operational complexity of Kafka or RabbitMQ.

The project is actively maintained with regular releases and a growing user community. Documentation covers common use cases, and the open-source nature means you can inspect the source code, contribute fixes, and adapt the tool to your specific requirements.

§02

How it saves time or tokens

Kafka requires ZooKeeper (or KRaft), topic partitioning design, and significant operational expertise. RabbitMQ needs Erlang and careful queue configuration. NATS runs as a single binary, connects in milliseconds, and handles millions of messages per second with sub-millisecond latency. JetStream adds persistence when you need it, without the overhead when you do not.

§03

How to use

  1. Start a NATS server using Docker or the binary download.
  2. Connect a publisher and subscriber using the NATS client library for your language.
  3. Enable JetStream for persistent messaging when you need at-least-once delivery.
§04

Example

# Start NATS with JetStream enabled
docker run -d --name nats -p 4222:4222 -p 8222:8222 nats:latest -js

# Publish a message
nats pub greetings 'Hello NATS'

# Subscribe to messages
nats sub greetings
// Go client example
package main

import (
    "fmt"
    "github.com/nats-io/nats.go"
)

func main() {
    nc, _ := nats.Connect(nats.DefaultURL)
    defer nc.Close()

    nc.Subscribe("orders.*", func(m *nats.Msg) {
        fmt.Printf("Received: %s\n", string(m.Data))
    })

    nc.Publish("orders.new", []byte(`{"id": 123}`))
}
§05

Related on TokRepo

§06

Common pitfalls

  • Without JetStream, NATS is fire-and-forget. Messages published when no subscriber is connected are lost. Enable JetStream for any workflow that requires message persistence.
  • NATS subject names are case-sensitive. Publishing to 'Orders.New' and subscribing to 'orders.new' will not match.
  • Cluster configuration requires explicit route definitions between nodes. Misconfigured routes cause split-brain scenarios where messages are delivered to only a subset of subscribers.

Before adopting this tool, evaluate whether it fits your team's existing workflow. Read the official documentation thoroughly, and start with a small proof-of-concept rather than a full migration. Community forums, GitHub issues, and Stack Overflow are valuable resources when you encounter edge cases not covered in the documentation.

Frequently Asked Questions

What is NATS JetStream?+

JetStream is NATS built-in persistence layer. It adds at-least-once and exactly-once delivery, message replay, consumer groups, and key-value storage on top of the core NATS pub/sub system. Enable it with the -js flag.

How does NATS compare to Kafka?+

NATS is simpler to operate (single binary, no ZooKeeper), has lower latency, and is designed for ephemeral messaging. Kafka excels at high-throughput log streaming with strong ordering guarantees. NATS JetStream bridges the gap for use cases that need both simplicity and persistence.

Which programming languages have NATS clients?+

NATS has official client libraries for Go, Python, Java, JavaScript/TypeScript, Rust, C#, Ruby, and C. Community clients exist for Elixir, Kotlin, Swift, and other languages.

Can NATS handle request/reply patterns?+

Yes. NATS has built-in request/reply support. A client sends a request on a subject, and one subscriber responds. This enables synchronous RPC-style communication over the messaging layer without a separate HTTP service.

Is NATS suitable for IoT workloads?+

Yes. NATS is designed for IoT with its lightweight protocol, leaf node architecture for edge deployments, and support for millions of concurrent connections. The NATS protocol overhead is minimal, making it suitable for constrained devices.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets