Skip to content

Widhian Bramantya

coding is an art form

Menu
  • About Me
Menu
Nats JetStream

NATS JetStream: Persistence and Streaming Made Simple

Posted on September 6, 2025September 6, 2025 by admin

In the previous article, I wrote an overview of NATS, explaining what it is, how it works, and why developers use it for building distributed systems. If you are new to NATS, I recommend reading that article first because it covers the basics like subjects, publishers, and subscribers.

In this article, let’s go a bit deeper and talk about JetStream, which is the persistence and streaming layer of NATS.

Why JetStream?

The original NATS is a lightweight messaging system. Messages are sent from publishers to subscribers, and once delivered, they are gone. This is fine for real-time communication, but in many cases, we need:

  • Persistence – messages should be stored and retrievable later.
  • Streaming – multiple consumers should be able to replay past messages.
  • Reliability – if a consumer is offline, it should still receive messages when it comes back.

That’s where JetStream comes in.

Key Features of JetStream

  1. Message Persistence
    • Messages are stored on disk (or memory if configured).
    • You can define how long messages should live (e.g., keep for 7 days or keep the last 1,000 messages).
  2. Replay and Streaming
    • Consumers can “rewind” and process messages from the past.
    • Useful for event sourcing, reprocessing logs, or auditing.
  3. Durable Consumers
    • Consumers can keep their position (offset) in the stream.
    • If a consumer disconnects, when it comes back it will continue from where it left off.
  4. At-Least-Once Delivery
    • JetStream ensures messages are not lost.
    • Consumers acknowledge messages when processed, otherwise JetStream will redeliver them.
  5. Flexible Storage Options
    • File-based (disk) for long-term persistence.
    • Memory-based for fast but short-lived data.
See also  Request–Reply in NATS: One-to-One Messaging

How JetStream Works

At the core of JetStream are Streams and Consumers:

  • Streams – a named collection of messages stored based on a subject pattern. For example, you can have a stream that stores all messages published to orders.*.
  • Consumers – subscribers that read from a stream. Consumers can be push-based (messages are delivered) or pull-based (messages are fetched on demand).

A simple flow looks like this:

  1. A publisher sends messages to a subject (orders.created).
  2. The stream ORDERS is configured to capture that subject.
  3. Consumers subscribe to ORDERS and can replay or process messages as needed.

Related posts:

Scalability and Reliability in NATS

Queue Groups in NATS: Load Balancing for Subscribers

Ensuring Message Ordering in NATS: A Kafka-like Approach

Pages: 1 2 3
Category: NATS

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Linkedin

Widhian Bramantya

Recent Posts

  • Smart Automation in PostgreSQL: Managing Time-Based Data with pg_partman and pg_cron
  • Understanding PostgreSQL WAL, Slot, Publication, LSN, and Replication Lag
  • PostgreSQL Write-Ahead Log (WAL): Durability, Performance Tuning, and Recovery Explained
  • PostgreSQL Replication Deep Dive: From High Availability to Multi-Master Clusters
  • Finding Nearby Merchants in a Ride-Hailing App Using Elasticsearch Polygon Search
  • Advanced Text Search in Elasticsearch: N-Gram, Reverse, Fuzzy, and Search-as-you-type
  • Understanding and Customizing Analyzers in Elasticsearch
  • Log Management at Scale: Integrating Elasticsearch with Beats, Logstash, and Kibana
  • Index Lifecycle Management (ILM) in Elasticsearch: Automatic Data Control Made Simple
  • Blue-Green Deployment in Elasticsearch: Safe Reindexing and Zero-Downtime Upgrades
  • Maintaining Super Large Datasets in Elasticsearch
  • Elasticsearch Best Practices for Beginners
  • Implementing the Outbox Pattern with Debezium
  • Production-Grade Debezium Connector with Kafka (Postgres Outbox Example – E-Commerce Orders)
  • Connecting Debezium with Kafka for Real-Time Streaming
  • Debezium Architecture – How It Works and Core Components
  • What is Debezium? – An Introduction to Change Data Capture
  • Offset Management and Consumer Groups in Kafka
  • Partitions, Replication, and Fault Tolerance in Kafka
  • Delivery Semantics in Kafka: At Most Once, At Least Once, Exactly Once

Recent Comments

No comments to show.

Archives

  • October 2025
  • September 2025
  • August 2025
  • November 2021
  • October 2021
  • August 2021
  • July 2021
  • June 2021
  • March 2021
  • January 2021

Categories

  • Debezium
  • Devops
  • ElasticSearch
  • Golang
  • Kafka
  • Lua
  • NATS
  • PostgreSQL
  • Programming
  • RabbitMQ
  • Redis
  • VPC
© 2026 Widhian Bramantya | Powered by Minimalist Blog WordPress Theme