Skip to main content

Introducing NatsPubsub 1.0

ยท 3 min read
Mike Attara
NatsPubsub Maintainer

We're excited to announce the release of NatsPubsub 1.0, a production-ready pub/sub messaging library for NATS JetStream!

What is NatsPubsub?โ€‹

NatsPubsub is a declarative pub/sub library that makes working with NATS JetStream effortless. Available in both JavaScript/TypeScript and Ruby, it brings battle-tested reliability patterns to your event-driven architecture.

Key Featuresโ€‹

๐ŸŽฏ Declarative APIโ€‹

Write clean, maintainable message handlers with a familiar, class-based API:

import { Subscriber, TopicMetadata } from "nats-pubsub";

class OrderCreatedSubscriber extends Subscriber<
Record<string, unknown>,
TopicMetadata
> {
constructor() {
super("production.myapp.order.created");
}

async handle(
message: Record<string, unknown>,
metadata: TopicMetadata,
): Promise<void> {
await processOrder(message);
}
}

๐Ÿ”’ Built-in Reliabilityโ€‹

  • Inbox/Outbox Pattern: Guaranteed message delivery with transactional guarantees
  • Dead Letter Queue: Automatic handling of failed messages
  • Automatic Retries: Exponential backoff with configurable retry strategies

๐ŸŒ Cross-Language Supportโ€‹

JavaScript and Ruby implementations use identical event formats, enabling seamless communication between polyglot microservices.

โšก Production Readyโ€‹

  • Comprehensive monitoring with Prometheus metrics
  • Health check endpoints
  • Structured logging
  • 95%+ test coverage

Getting Startedโ€‹

JavaScript/TypeScriptโ€‹

npm install nats-pubsub
import NatsPubsub from "nats-pubsub";

NatsPubsub.configure({
natsUrls: "nats://localhost:4222",
env: "production",
appName: "my-app",
});

await NatsPubsub.publish("order.created", {
orderId: "123",
amount: 99.99,
});

Rubyโ€‹

gem install nats_pubsub
require 'nats_pubsub'

NatsPubsub.configure do |config|
config.nats_urls = 'nats://localhost:4222'
config.env = 'production'
config.app_name = 'my-app'
end

NatsPubsub.publish(
topic: 'order.created',
message: {
order_id: '123',
amount: 99.99
}
)

Why NatsPubsub?โ€‹

vs. Raw NATS Clientโ€‹

  • โœ… Declarative subscriber API (vs. imperative callbacks)
  • โœ… Built-in reliability patterns (vs. manual implementation)
  • โœ… Comprehensive testing utilities
  • โœ… Auto-topology management
  • โœ… Framework integrations (Rails, Express, NestJS)

vs. Kafkaโ€‹

  • โœ… Simpler operations (no ZooKeeper)
  • โœ… Lower latency (<1ms vs. 5-50ms)
  • โœ… Smaller resource footprint
  • โœ… Built-in request/reply pattern

vs. RabbitMQโ€‹

  • โœ… Higher performance (2-10x throughput)
  • โœ… Simpler configuration
  • โœ… Better cloud-native support
  • โœ… Built-in message persistence

What's Next?โ€‹

We're committed to making NatsPubsub the best pub/sub library for NATS JetStream. Upcoming features include:

  • Enhanced observability with OpenTelemetry integration
  • GraphQL subscriptions support
  • Additional language implementations (Python, Go)
  • Cloud deployment templates (AWS, GCP, Azure)

Get Involvedโ€‹

Acknowledgmentsโ€‹

Special thanks to the NATS community and all early adopters who provided feedback during the beta phase. Your input was invaluable in shaping this release.


Ready to get started? Check out our documentation and start building event-driven applications today!