Message Queue Overview
Enterprise-grade message queue with NATS, the high-performance cloud-native messaging system.
What is NATS?
NATS is a simple, secure, and high-performance messaging system designed for cloud-native applications, IoT messaging, and microservices architectures. SailOps provides fully managed NATS clusters with JetStream for:
- Pub/Sub messaging - Real-time event broadcasting
- Request/Reply - Synchronous service communication
- Queue groups - Load-balanced message distribution
- Persistent streams - Message replay and durability
- Key-Value stores - Distributed configuration
- Object stores - Large file storage
Supported Versions
| Version | Status |
|---|---|
| NATS 2.10 | ✓ Supported |
| NATS 2.11 | ✓ Supported |
| NATS 2.12 | ✓ Supported |
Key Features
Cloud-Native Design
NATS is built for modern architectures:
- Ultra-lightweight footprint
- No external dependencies
- Built-in clustering
- Multi-tenancy support
High Performance
Optimized for speed and scale:
- Millions of messages per second
- Sub-millisecond latency
- Minimal memory overhead
- Horizontal scaling
JetStream
Built-in persistence layer:
- Streams - Persistent message storage
- Consumers - Flexible message delivery
- Key-Value - Distributed key-value stores
- Object Store - Large binary object storage
Managed Service
SailOps handles operations:
- Automatic provisioning
- Monitoring and metrics
- High availability clustering
- Security updates
Use Cases
Event-Driven Architecture
Decouple services with pub/sub messaging:
// Publisher
await nc.publish('orders.created', JSON.stringify({
orderId: 'order-123',
customerId: 'cust-456',
total: 99.99
}));
// Subscriber
const sub = nc.subscribe('orders.created');
for await (const msg of sub) {
const order = JSON.parse(msg.data);
await processOrder(order);
}
Microservices Communication
Request/Reply pattern for service calls:
// Service
const sub = nc.subscribe('users.get');
for await (const msg of sub) {
const { userId } = JSON.parse(msg.data);
const user = await db.getUser(userId);
msg.respond(JSON.stringify(user));
}
// Client
const response = await nc.request('users.get', JSON.stringify({ userId: '123' }));
const user = JSON.parse(response.data);
Work Queues
Distribute work across multiple workers:
// Multiple workers subscribe to the same queue group
const sub = nc.subscribe('tasks.process', { queue: 'workers' });
for await (const msg of sub) {
const task = JSON.parse(msg.data);
await processTask(task);
}
Real-Time Notifications
Push notifications to connected clients:
// Server pushes notifications
await nc.publish(`notifications.user.${userId}`, JSON.stringify({
type: 'new_message',
from: 'John',
preview: 'Hey, how are you?'
}));
// Client receives notifications
const sub = nc.subscribe(`notifications.user.${userId}`);
for await (const msg of sub) {
displayNotification(JSON.parse(msg.data));
}
Architecture
JetStream Components
Streams
Persistent message storage with configurable retention:
| Policy | Description |
|---|---|
| Limits | Retain messages until limits are reached |
| Interest | Retain while consumers are subscribed |
| Work Queue | Each message delivered once then deleted |
Consumers
Flexible message consumption:
- Push - Messages delivered to subscribers
- Pull - Clients pull messages on demand
- Durable - State persists across reconnections
- Ephemeral - Temporary consumers
Key-Value Stores
Distributed key-value storage:
- Key history and versioning
- TTL support
- Watch for changes
- Atomic operations
Object Stores
Large binary object storage:
- Store files up to 5GB
- Chunked uploads
- Metadata support
- Streaming downloads
Compute Classes
NATS clusters use compute classes with fixed CPU:RAM ratios:
| Class | CPU:RAM Ratio | Small | Medium | Large | XLarge |
|---|---|---|---|---|---|
| Eco | 1:2 | 0.5 / 1 Gi | 1 / 2 Gi | 2 / 4 Gi | 3 / 6 Gi |
| Standard | 1:4 | 1 / 4 Gi | 2 / 8 Gi | 4 / 16 Gi | 15 / 58 Gi |
| Production | 1:4 | 1 / 4 Gi | 2 / 8 Gi | 4 / 16 Gi | 6 / 28 Gi |
Format: vCPU / Memory
Replicas
Configure cluster size for availability:
| Replicas | Description |
|---|---|
| 1 | Single node, no replication (development) |
| 3 | High availability (recommended for production) |
| 5 | Enhanced fault tolerance |
| 7 | Maximum fault tolerance |
- Use 1 replica for development and testing
- Use 3 replicas for production workloads
- Use 5-7 replicas for critical systems requiring maximum availability
Security
Network Access
By default, NATS clusters are accessible from:
- Containers in the same project
- Internal project network
Public Access (Optional)
Enable external access to your NATS cluster:
- Go to cluster settings
- Enable Public Access
- Configure the IP Allowlist — add each allowed CIDR and an optional note (up to 100 characters) to identify its purpose
When enabled, only allowlisted IPs can connect from outside your project.
Authentication
Password authentication protects your cluster:
const nc = await connect({
servers: 'nats://my-cluster.my-project:4222',
user: 'admin',
pass: 'your-password'
});
Transport Encryption
Managed NATS clusters currently expose plain NATS endpoints (nats://) on
both the internal network and optional public access. TLS configuration is not
available yet and is rejected by the API; public access therefore does not
add transport encryption. Keep sensitive traffic on the private project
network and use password authentication until managed TLS support is available.
Monitoring
Built-in Metrics
- Connection count
- Message rate (in/out)
- Byte throughput
- Stream storage usage
- Consumer lag
Viewing Metrics
- Go to your NATS cluster
- Click Observability tab
- Select time range
- View performance charts
Pricing
NATS clusters are billed per-hour based on:
- Compute class and resources
- Number of replicas
- JetStream storage usage
See Billing for detailed pricing information.
Best Practices
1. Use Meaningful Subject Names
Organize subjects hierarchically:
orders.created
orders.updated
orders.{orderId}.status
payments.processed
payments.failed
2. Configure Appropriate Retention
Match retention to your use case:
- Limits: When you need message history
- Interest: When messages are only for active consumers
- Work Queue: When each message should be processed once
3. Use Consumer Groups for Scaling
Distribute load across workers:
// All workers in the same queue group share the load
const sub = nc.subscribe('tasks.*', { queue: 'task-workers' });
4. Monitor Consumer Lag
Set alerts for consumer lag to detect processing delays.
5. Use Durable Consumers for Reliability
Durable consumers maintain state across restarts:
const consumer = await js.consumers.get('ORDERS', 'order-processor');