What NATS Is
Outcome: a picture of NATS you can reason with — one server, messages published under names, copies delivered to whoever asked for those names — and the one design decision everything else follows from.
The problem it removes
Imagine three small programs: a till that records sales, a stock keeper that watches inventory, and a noticeboard that shows the day's totals. Each needs to hear about every sale. The till could call the other two directly — but then the till must know where they live, what to do when one is asleep, and how to add a fourth listener next month without editing the till again.
NATS takes the introduction away. Every program connects to the same server and speaks one simple language:
- Publish: "here is a message, its name is
shop.order.1, its content is these bytes." - Subscribe: "send me a copy of every message whose
name matches
shop.>"
The name is called the subject. The till publishes a sale once, under a subject, and never learns who received it. The stock keeper and the noticeboard subscribe, and each gets its own copy. A fourth listener next month is its own decision, not the till's problem. Programmers call this decoupling; in plain terms, nobody needs anybody else's address, hours, or permission.
The design decision: the core forgets
Core NATS delivers a message to the subscribers who are connected at that moment, and then it is done. There is no disk, no queue kept for later, no "you have 3 unread messages". If a program is down when its message passes, the message is simply not in its life.
That sounds like a flaw until you see what it buys. A server that stores nothing can be tiny and very fast — the lab's single server pushed roughly 190,000 small messages a second through one publisher and one subscriber on a small shared machine (transcript t12, and chapter 13 is honest about what that number does and does not mean). No disk also means no disk to fill, wear out, back up, or corrupt. For a large class of traffic — readings, events, "this just happened" — forgetting is the correct behaviour. A temperature reading from an hour ago is not news; the next one is already coming.
Chapter 4 makes this concrete: a message published before its subscriber started is simply absent from the subscriber's life, and the transcript shows the gap.
The second half: JetStream remembers
Sometimes forgetting is wrong. An order must not vanish because the order program was restarting. For those subjects, NATS has a second layer called JetStream, built into the same server. You declare a stream: a named net stretched across some subjects, which keeps a copy of every message on disk. Programs then read from the stream through consumers, which track who has read what, wait for each reader to acknowledge ("processed, you may let it go"), and offer the message again if the acknowledgement never comes.
The important part is that this is opt-in per subject
tree, not a different product. The till still publishes
to shop.order.1 the same way. Whether that subject is
also caught by a stream is the stream's business.
Chapters 8 and 9 run all of it: a stream that caught
three messages, a consumer that read them in order, one
message deliberately left unacknowledged and duly
redelivered, and a server restart that lost nothing.
Two everyday tools are built from streams, and both get a workout in chapter 9: a key-value store (a stream wearing the shape of a settings table, each value keeping its revision history) and an object store (a stream that holds whole files in chunks).
A first taste
After installing (chapter 3), the whole idea is two terminal windows. In one:
nats sub greetings
In the other:
nats pub greetings "hello one"
The first window prints the message. Nothing was configured but a single server in the middle, and the publisher has no idea the subscriber exists. Everything in this guide is an elaboration of that exchange.
Where NATS comes from
NATS began at Apcera and is now a Cloud Native Computing Foundation project, written in Go and published as open source (the server under the Apache 2.0 licence). It is known in the trade as connective tissue: microservices, edge devices, and control planes use it where a heavy broker would be too much machinery. Its whole client protocol fits in a short document, which is why clients exist for dozens of languages — and why the command-line tool in this guide can exercise every idea in it.
Check: you should now be able to say, in one sentence each, what publish and subscribe mean, why the core forgetting is a feature, and what JetStream adds. If the third one is fuzzy, that is fine — chapter 8 is built to make it concrete.