NATS is a messaging system for services that need to talk to each other. One service publishes a message to a subject like orders.created, and any service subscribed to that subject receives it — instantly, with almost no setup. It is the tool you reach for when your app has grown past one server and its parts need a fast, simple way to communicate.
How it works: services connect to a NATS server and either publish messages or subscribe to subjects. Subjects support wildcards, so orders.* catches every order event. NATS also supports request-reply (ask a question, get one answer) and queue groups (spread work across several workers). The server itself is a single small binary with no dependencies, and it starts in milliseconds.
NATS is a good fit for beginners because there is almost nothing to configure. No clusters to plan, no partitions to tune, no schema registry. Publish a message, subscribe to it, and you have a working event flow in an afternoon. The client libraries are thin and consistent across languages, so a Python service and a Go service talk to each other with the same few lines of code.
A quick example — publishing and subscribing in Python:
import asyncio
from nats.aio.client import Client as NATS
async def main():
nc = NATS()
await nc.connect("nats://localhost:4222")
async def handler(msg):
print("Got order:", msg.data.decode())
await nc.subscribe("orders.created", cb=handler)
await nc.publish("orders.created", b'{"id": 42}')
await asyncio.sleep(1)
asyncio.run(main())
That is the whole pattern: connect, subscribe, publish.
Who is it for? Developers splitting a monolith into services; teams building event-driven features like notifications and order processing; students learning how distributed systems communicate.
Limits to know: plain NATS is fire-and-forget — if no subscriber is listening, the message is gone. For durable delivery you need JetStream, the built-in persistence layer, which adds concepts to learn. And for heavy data pipelines with complex routing, a bigger broker like Kafka may fit better.
To start today: run the NATS server binary, write one publisher and one subscriber in your favourite language, and send your first message between them.
Top comments (0)