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  Publish–Subscribe in NATS: Simple and Powerful 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.
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

  • 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
  • Producers and Consumers: How Data Flows in Kafka
  • Kafka Architecture Explained: Brokers, Topics, Partitions, and Offsets
  • Getting Started with Apache Kafka: Core Concepts and Use Cases
  • Security Best Practices for RabbitMQ in Production
  • Understanding RabbitMQ Virtual Hosts (vhosts) and Their Uses
  • RabbitMQ Performance Tuning: Optimizing Throughput and Latency
  • High Availability in RabbitMQ: Clustering and Mirrored Queues Explained

Recent Comments

  1. Playing with VPC AWS (Part 2) – Widhian's Blog on Playing with VPC AWS (Part 1): VPC, Subnet, Internet Gateway, Route Table, NAT, and Security Group
  2. Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh – Widhian's Blog on Basic Concept of ElasticSearch (Part 1): Introduction
  3. Basic Concept of ElasticSearch (Part 2): Architectural Perspective – Widhian's Blog on Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh
  4. Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh – Widhian's Blog on Basic Concept of ElasticSearch (Part 2): Architectural Perspective
  5. Basic Concept of ElasticSearch (Part 1): Introduction – Widhian's Blog on Basic Concept of ElasticSearch (Part 2): Architectural Perspective

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
  • Programming
  • RabbitMQ
  • Redis
  • VPC
© 2025 Widhian Bramantya | Powered by Minimalist Blog WordPress Theme