Why Messaging Systems Matter
In modern software, applications rarely work alone. A mobile app might need to talk to a backend service. That backend service might need to talk to a payment gateway, and the payment system may need to update analytics. Instead of building a direct web of connections, developers often use a messaging system.
A messaging system acts like a mail delivery service. You don’t hand every letter directly to the receiver. Instead, you drop it at the post office, and the system takes care of delivery. This pattern makes applications simpler, faster to scale, and easier to maintain.
There are many messaging systems out there: Kafka, RabbitMQ, ActiveMQ, MQTT. Each has its own strengths and weaknesses. Among them, NATS has become popular for developers who need something lightweight, extremely fast, and cloud-native.
What is NATS?
NATS is an open-source messaging system originally built by Derek Collison in 2011. Its philosophy is very clear: simplicity, performance, and scalability.
At its core, NATS is:
- A publish/subscribe system (you publish a message, others subscribe to it).
- A request/reply system (like sending a question and waiting for an answer).
- A queueing system (messages can be load-balanced between workers).
Unlike heavier systems such as Kafka, NATS can be run with a single small binary file. It takes only a few seconds to set up and can handle millions of messages per second with very low latency.
Think of NATS as the WhatsApp for your services. You send a message to a group (subject), and everyone in that group can instantly receive it.
Core Concepts in NATS

Publish/Subscribe
In this model, a publisher sends messages on a subject (like a channel name). Any number of subscribers can listen to that subject.
Example:
- A service publishes
OrderPlaced
events. - Multiple services subscribe: one for billing, one for analytics, and another for shipping.
This decouples the services. They don’t need to know each other directly, only the subject they care about.
Request/Reply
NATS also supports direct request/response messaging.
- A client asks a question (e.g., “What is the user profile for ID 123?”).
- Another service replies with the data.
This feels similar to making an API call but with the advantage of NATS’s speed and reliability.
Queue Groups
When multiple subscribers join the same queue group, NATS will deliver each message to only one member of the group.
This is perfect for load balancing:
- Imagine you have 5 worker services processing incoming images.
- Instead of every worker processing the same message, NATS ensures each worker gets a unique one
JetStream (Persistence Layer)
By default, NATS is fire-and-forget. If a subscriber is offline, it will miss the messages.
For cases where you cannot lose messages, NATS offers JetStream.
JetStream allows:
- Message persistence (saved on disk or memory).
- Replay (consume from the past).
- Retention policies (keep all messages, only last X, or only while subscribers exist).
This makes NATS powerful enough for event sourcing, audit logs, or data pipelines.
Key-Value (KV) Store
Built on top of JetStream, NATS can act as a distributed key-value database.
- Each bucket stores key-value pairs.
- Changes are versioned, so you can watch updates like a log.
- Useful for configuration management, feature flags, or lightweight state sharing between services.
Comparison Table of NATS Features
Feature | How It Works | Best Use Case | Persistence | Delivery Pattern |
---|---|---|---|---|
Publish/Subscribe | One publisher, many subscribers. Everyone interested in the subject gets the message. | Broadcasting events (e.g., OrderPlaced) | No | Fan-out to all subs |
Request/Reply | A client sends a request and waits for one service to reply. | RPC-like interactions (e.g., get user profile) | No | One-to-one |
Queue Groups | Subscribers in the same group share the load. One message goes to one worker. | Task distribution, worker pools | No | Load balancing |
JetStream | Messages are stored durably, can be replayed, with policies (limits, work queue, interest). | Event sourcing, audit logs, guaranteed delivery | Yes | Configurable (at-least-once, etc.) |
Key-Value (KV) | Key-value buckets stored on top of JetStream, with versioning and watch support. | Config sharing, feature flags, lightweight state | Yes | Change notifications |