Skip to main content

Why JetStream?

Use whenyou are deciding whether the built-in NestJS NATS transport is already enough.

You getthe line where Core NATS stops being enough, and what this library adds over raw JetStream.

The built-in NestJS NATS transport runs on Core NATS: fire-and-forget pub/sub with no persistence. This page marks the line where that stops being enough.

Stay on the built-in transport when​

  • Messages are idempotent hints, like a cache invalidation or a metric update.
  • Losing one is acceptable, because retrying or recomputing is cheap.
  • No consumer needs history.
  • Latency is the thing you tune for, ahead of durability.

Persistence costs disk I/O, stream provisioning and consumer state. If the list above describes your workload, stop here.

Where Core NATS drops messages​

SituationCore NATSWith this library
Pod gets SIGTERM with 40 messages in flightAll 40 are gone: the publisher was already ackedMessages return to pending, the next pod takes them
Downstream is down for 3 minutes200 events delivered into the voidEvents wait in the stream, processed in order on return
Handler throws on a specific payloadLost on the first throwRetried to max_deliver (default 3), then written to the DLQ stream with tracking headers
New service needs the last 7 daysCustom backfill job against the databaseA consumer with deliver_policy by start time replays the stream
New replica missed a broadcast during startupNo answerPer-service durable consumers catch it up

The first row needs one line from you: call app.enableShutdownHooks() so NestJS runs the shutdown lifecycle. See Graceful Shutdown and Dead Letter Queue.

What the library adds over raw JetStream​

Driving JetStream from the @nats-io/* packages directly means building this yourself:

Delivery

Durability and recovery

Publishing

Operations

Every item sits behind @EventPattern, @MessagePattern and ClientProxy.

HTTP, Core NATS or JetStream​

Best atCost
HTTPRequest/response with mature toolingCouples caller and callee in time; retries and circuit breakers are yours
Core NATSLow-latency in-cluster RPCNo persistence
JetStreamWork that must not be lostDisk I/O, stream and consumer state

Most systems run all three. HTTP serves the edge, and internally the split is Core NATS for hot calls against JetStream for durable events. RPC mode is per module (rpc.mode: 'core' or 'jetstream') while @EventPattern stays on durable delivery.

Other NestJS NATS packages​

PackageFocus
@nestjs/microservicesOfficial Core NATS integration, maintained by the NestJS team
@nestjs-plugins/nestjs-nats-jetstream-transportCommunity JetStream transport
@mirasys/nestjs-jetstream-transporterCustom JetStream transporter
@horizon-republic/nestjs-jetstreamThis library: DLQ, health indicators, broadcast, ordered delivery, tracing

Don't use this library when​

  • You don't run NATS. Operating it costs real time. Solve the problem you have now.
  • Your workload is request/response without durability. The built-in transport is lighter.
  • You need cross-region replication under strict latency SLAs. Mirrors and sources exist, though tuning them for multi-region is its own project.
  • You're prototyping.

Next​