NATS
Overview
NATS is a simple, secure, high-performance messaging system for cloud-native applications, edge devices, and microservices, and is a CNCF project. Core NATS provides fast at-most-once pub/sub and request-reply; the JetStream layer adds persistence, replay, and stronger delivery guarantees plus key/value and object stores. Read this when you want lightweight, low-latency messaging with optional durability without operating a heavier broker.
Official sources
Install / setup
docker pull nats:latest
docker run -p 4222:4222 -ti nats:latest
# macOS (Homebrew)
brew install nats-server
Core concepts
- Subjects: hierarchical, dot-delimited addresses (e.g.
orders.us.new) that messages are published to and subscribed against, with * and > wildcards.
- Publish / Subscribe: many subscribers can receive messages on a subject; Core NATS delivery is at-most-once and fire-and-forget.
- Request-Reply: built-in RPC pattern where a publisher gets a direct reply on a temporary inbox subject.
- Queue groups: subscribers sharing a queue group load-balance messages so each message goes to one member — work-queue semantics over pub/sub.
- JetStream: the persistence engine adding streams, durable consumers, replay, and up to exactly-once delivery on top of Core NATS.
- KV and Object stores: higher-level abstractions built on JetStream for key/value and large-object storage.
Best practices
- Design subject hierarchies intentionally and use wildcards for flexible subscriptions rather than hard-coding many concrete subjects.
- Use queue groups for scalable work distribution so adding subscribers spreads load automatically.
- Use JetStream (not Core NATS) whenever you need messages to survive subscriber downtime, replay, or acknowledgements.
- Run a clustered nats-server for high availability rather than a single node in production.
Common pitfalls
- Expecting Core NATS to retain messages → it is at-most-once and drops messages with no active subscriber; use JetStream for persistence.
- Forgetting to ack JetStream messages → unacked messages are redelivered per the consumer's ack policy, causing duplicate processing.
- Overly broad
> wildcard subscriptions → can flood a subscriber with far more traffic than intended.
Examples
# subscribe to a subject (NATS CLI)
nats sub "orders.>"
# publish a message
nats pub orders.us.new '{"id":99}'
Further reading
Related skills
- ../kafka — log-based streaming for very high-throughput, replay-heavy pipelines
- ../rabbitmq — broker with rich routing when you need protocol breadth and per-message acks
1---2name: nats3description: Lightweight high-performance messaging system with pub/sub and JetStream persistence; consult for cloud-native, edge, and microservice messaging.4domain: stack5category: queue6tags: [nats, messaging, pubsub, jetstream, cloud-native, streaming]7official_sources:8 - https://docs.nats.io/9 - https://github.com/nats-io/nats-server10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/nats13---1415# NATS1617## Overview18NATS is a simple, secure, high-performance messaging system for cloud-native applications, edge devices, and microservices, and is a CNCF project. Core NATS provides fast at-most-once pub/sub and request-reply; the JetStream layer adds persistence, replay, and stronger delivery guarantees plus key/value and object stores. Read this when you want lightweight, low-latency messaging with optional durability without operating a heavier broker.1920## Official sources21- Docs: https://docs.nats.io/22- Repo: https://github.com/nats-io/nats-server23- Install: https://docs.nats.io/running-a-nats-service/introduction/installation2425## Install / setup26```bash27docker pull nats:latest28docker run -p 4222:4222 -ti nats:latest29```30```bash31# macOS (Homebrew)32brew install nats-server33```3435## Core concepts36- **Subjects**: hierarchical, dot-delimited addresses (e.g. `orders.us.new`) that messages are published to and subscribed against, with `*` and `>` wildcards.37- **Publish / Subscribe**: many subscribers can receive messages on a subject; Core NATS delivery is at-most-once and fire-and-forget.38- **Request-Reply**: built-in RPC pattern where a publisher gets a direct reply on a temporary inbox subject.39- **Queue groups**: subscribers sharing a queue group load-balance messages so each message goes to one member — work-queue semantics over pub/sub.40- **JetStream**: the persistence engine adding streams, durable consumers, replay, and up to exactly-once delivery on top of Core NATS.41- **KV and Object stores**: higher-level abstractions built on JetStream for key/value and large-object storage.4243## Best practices44- Design subject hierarchies intentionally and use wildcards for flexible subscriptions rather than hard-coding many concrete subjects.45- Use queue groups for scalable work distribution so adding subscribers spreads load automatically.46- Use JetStream (not Core NATS) whenever you need messages to survive subscriber downtime, replay, or acknowledgements.47- Run a clustered nats-server for high availability rather than a single node in production.4849## Common pitfalls50- Expecting Core NATS to retain messages → it is at-most-once and drops messages with no active subscriber; use JetStream for persistence.51- Forgetting to ack JetStream messages → unacked messages are redelivered per the consumer's ack policy, causing duplicate processing.52- Overly broad `>` wildcard subscriptions → can flood a subscriber with far more traffic than intended.5354## Examples55```bash56# subscribe to a subject (NATS CLI)57nats sub "orders.>"58# publish a message59nats pub orders.us.new '{"id":99}'60```6162## Further reading63- https://docs.nats.io/nats-concepts/jetstream — JetStream persistence concepts64- https://docs.nats.io/nats-concepts/core-nats — Core NATS messaging patterns6566## Related skills67- ../kafka — log-based streaming for very high-throughput, replay-heavy pipelines68- ../rabbitmq — broker with rich routing when you need protocol breadth and per-message acks