From the beginning, NATS has been a pub/sub system. While it does a lot more than pub/sub now, all other features are built on its pub/sub primitives.

NATS: First impressions

submited by
Style Pass
2024-04-03 00:00:05

From the beginning, NATS has been a pub/sub system. While it does a lot more than pub/sub now, all other features are built on its pub/sub primitives. This makes for a simple and predictable protocol.

It makes sense that pub/sub is the foundation for NATS; it's the most basic way for two systems to communicate. It's completely async and ephemeral. Publishers publish to topics and subscribers subscribe to them. No one needs an address, just subjects that they publish or subscribe to.

On top of pub/sub, NATS has a request/reply mechanism. The "request" is just a pub, except it includes a special handle that tells the responder where to reply (the reply-to part above). The NATS client subscribes to the reply-to and blocks after publishing, awaiting a reply.

If there are no responders available, you can have your request wait until a responder gets to it for some timeout. Or, you can have your request fail immediately.

Leave a Comment