NATS
Services use NATS to send messages without contacting one another directly. Core NATS routes messages to active subscribers, while JetStream can store messages for later delivery or replay.
What NATS does
NATS is a messaging system for applications. An order service can announce that it created an order without knowing which services care about the event. A notification service and an analytics service can each subscribe to the event and act on it independently. The publisher sends the message to NATS rather than making a separate API call to each recipient.
How Core NATS routes messages
Each message is published to a subject, a name such as orders.created. NATS forwards the message to active subscriptions that match that name. A subscription can use a wildcard: orders.* matches orders.created and orders.cancelled, but not orders.eu.created, because * matches exactly one segment.
Independent subscriptions each receive a copy. When several workers subscribe to the same subject as members of a queue group, NATS sends each message to one member of that group. This spreads work across replicas while still letting independent subscribers see every event. Core NATS also supports request–reply: the requester supplies a reply subject and waits for a response up to a timeout.
Try it with two terminals
With a local NATS server running, start the subscriber before publishing:
# Terminal 1
nats sub 'orders.*'
# Terminal 2
nats pub orders.created '{"order_id":42}'
Stop the subscriber, publish another message, and restart it. The message published during the gap will not appear. Core NATS provides at-most-once delivery: it does not retain messages for disconnected subscribers or retry delivery when a worker fails. A queue group changes who gets a message, not whether it is stored.
When to use JetStream
Core NATS fits live signals you can afford to miss, such as refresh hints for a dashboard that periodically fetches the current state anyway. Use JetStream, NATS's built-in persistence layer, when a worker needs to catch up after downtime or replay saved events. A stream stores messages from configured subjects according to its retention settings. A consumer tracks delivery and can require acknowledgments. If an acknowledgment does not arrive in time, JetStream can redeliver the message. Replay is limited to what the stream still retains.
What comes up in interviews
Suppose a worker charges a customer and then crashes before acknowledging the event. JetStream may deliver it again, even though the charge already went through. A good answer distinguishes the broker's acknowledgment that it stored a message from the worker's acknowledgment that it processed one. Acknowledge only after committing the result, and make the side effect safe to retry: for instance, send the same idempotency key to the payment provider on every attempt.