Publish/Subscribe (Pub/Sub) is a messaging pattern where publishers send messages to specific topics or subjects, and subscribers receive messages by subscribing to those topics. In the NATS ecosystem, Pub/Sub is a core feature enabling real-time, decoupled communication between producers and consumers. This architecture supports scalability, flexibility, and low-latency message delivery, making it ideal for modern distributed systems.
Subject-Based Addressing
Dynamic Scalability
Load Balancing
Flexible Delivery Options
Multi-Protocol Support
Real-Time Notifications
IoT Data Streaming
Microservices Communication
Collaborative Applications
Monitoring and Alerts
| Aspect | Publish/Subscribe (e.g., NATS) | Point-to-Point Messaging |
|---|---|---|
| Communication Model | Decoupled, one-to-many or many-to-many. | Direct, one-to-one communication. |
| Scalability | Highly scalable; supports dynamic participants. | Limited to fixed endpoints and routing. |
| Flexibility | Topics/subjects allow dynamic message routing. | Requires pre-configured addresses. |
| Use Cases | Ideal for real-time, event-driven systems. | Best for synchronous, direct interactions. |
| Fault Tolerance | Resilient to participant failures. | Dependent on both endpoints being available. |
NATS Core:
Subjects and Wildcards:
Queue Groups:
JetStream:
Leaf Nodes:
Monitoring Tools:
NATS is designed for resource-constrained environments. The NATS server is a single ~20MB binary with no JVM or runtime dependencies. It runs on ARM, MIPS, and x86 architectures, starts in milliseconds, and maintains a minimal RAM footprint. This makes NATS suitable for deploying pub/sub messaging directly on embedded devices, industrial gateways, and IoT hardware. Learn more about NATS
NATS natively supports pub/sub, request-reply, fan-out, and queue-based load balancing on a single connection. There is no need for separate systems or protocol bridges between patterns. A single NATS connection lets IoT devices publish telemetry, respond to commands, and join work queues. Learn more about NATS request-reply
NATS can be embedded directly into applications or run as a standalone single binary. Leaf nodes operate fully independently during network disconnections, handling all local message routing without requiring a central broker. When connectivity returns, the leaf node automatically syncs with the broader NATS network. Learn more about NATS leaf nodes
NATS supports both synchronous and asynchronous patterns — the distinction applies to both interaction and behavior. Core NATS request-reply blocks the caller and waits for a response, making the interaction synchronous. JetStream publish also blocks by default, waiting for a server acknowledgment that the message was persisted. For non-blocking workflows, JetStream provides PublishAsync, which returns a PubAckFuture that resolves when the server confirms storage. On the service side, a handler can process the message synchronously and return a result, or it can queue the work internally and immediately reply with an acknowledgment — the caller does not need to know which approach the service uses. This flexibility lets you mix synchronous request-reply for real-time queries with asynchronous processing for heavier workloads, all on the same NATS connection. Learn more about NATS request-reply
NATS does not use a connection pool. Each nats.Connect call creates exactly one TCP connection, and all subscriptions and publishers are multiplexed over that single connection. There is one reader on the connection that receives the raw TCP byte stream and parses NATS protocol messages, which are then dispatched to the appropriate subscription handlers. The server URLs passed to nats.Connect are seed servers — the client randomly picks one, connects, and then learns about other servers in the cluster through server gossip. You do not always need to rely on a single connection per process. If subscribers or publishers on one connection are competing and you observe increased latency, establish a second connection so messages can be received and processed in parallel. In the extreme case where the TCP connection itself is saturated, split the workload across connections — and if the NIC is saturated, you need a separate host. Learn more about NATS connections
Last updated: March 2026
The Publish/Subscribe pattern is a core capability of NATS, enabling flexible, scalable, and real-time messaging for modern distributed applications. Its subject-based routing and dynamic scalability make it a cornerstone of event-driven and IoT-based architectures.
News and content from across the community