Qaze Logo
Back to NATS Knowledge Base
JetStream

What is JetStream?

JetStream is an advanced, distributed system for building and managing message streams within the NATS ecosystem. It extends the basic capabilities of NATS by providing robust, high-performance streaming and reliable message delivery with a rich set of features. This article explores what JetStream is, how it enhances the NATS ecosystem, and the key features that make it a powerful tool for developers.

Introduction to JetStream

JetStream is designed to offer advanced streaming capabilities on top of the core NATS messaging system. While NATS itself provides low-latency, lightweight messaging, JetStream brings in the ability to handle large volumes of data with features such as message durability, at-least-once delivery, and high availability.

Core Features of JetStream

  1. Message Persistence: Unlike basic NATS, which is designed for ephemeral message passing, JetStream ensures message persistence. Messages can be stored durable across disk storage, providing reliability in the event of failures.

  2. Consumer Delivery Semantics: JetStream supports multiple delivery semantics, including:

    • At Least Once: Ensures that each message is delivered to a consumer at least once, providing resilience to application crashes.
    • At Most Once: Ensures that each message is delivered at most once, useful for real-time data processing where duplication can be harmful.
    • Exactly Once: This is a theoretical concept in many systems but very hard to guarantee due to distributed system complexities. JetStream aims to get as close as possible to this semantic.
  3. High Availability: JetStream can be configured for high availability (HA) to ensure that there are no single points of failure. Data is replicated across multiple nodes, and in the event of a node failure, another node can take over without data loss.

  4. Scalability: It is designed to scale horizontally. As your data volume grows, you can add more nodes to the JetStream cluster to handle increased load and storage requirements.

  5. Rich API Support: JetStream offers a comprehensive API that allows developers to create, manage, and consume streams with ease. These APIs are available across multiple languages, making it versatile for different technology stacks.

  6. Flexible Storage Options: You can configure the storage backend (memory or file) based on your application’s requirements. Memory storage is suitable for high-speed, transient data, while file storage provides long-term durability.

  7. Stream Management: JetStream offers powerful stream management capabilities, including the ability to paginate through messages, create message filters, and manage message retention policies.

  8. Observability: With built-in observability, JetStream provides detailed metrics and monitoring capabilities, allowing operators to gain insights into the performance and health of their streaming infrastructure.

  9. Security: JetStream integrates with the NATS security model, supporting TLS encryption, authentication, and authorization to ensure that message streams are protected.

Use Cases for JetStream

  1. Data Ingestion and Processing: For applications that require reliable data ingestion and real-time processing, JetStream offers the necessary durability and performance.

  2. Event Sourcing: In event-driven architectures, JetStream can be used to persist events, allowing you to replay them for state reconstruction or debugging purposes.

  3. Log Aggregation: JetStream can be employed to aggregate logs from multiple sources, providing a durable and searchable log storage system.

  4. IoT Applications: In IoT systems, where devices generate continuous streams of data, JetStream ensures that this data is reliably captured and delivered.

  5. Financial Systems: For financial applications that demand high reliability and exactly-once delivery semantics, JetStream fits well by ensuring message integrity and durability.

Conclusion

JetStream significantly expands the capabilities of the NATS ecosystem by introducing advanced messaging features that address the needs of modern applications. Whether you are dealing with high-throughput data streams, requiring message durability, or needing robust delivery semantics, JetStream provides a comprehensive solution to these challenges. By leveraging JetStream, developers can build resilient, scalable, and high-performance messaging systems with ease.