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

Example Use Cases with Subject Patterns

One of the strengths of NATS (and JetStream) is the subject pattern system. Subjects are like channels, and you can use wildcards to organize messages into logical groups. Here are some practical use cases:

1. Order Processing in E-Commerce

  • Subjects:
    • orders.created
    • orders.paid
    • orders.shipped
  • How it works:
    • A checkout service publishes to orders.created whenever a new order is placed.
    • A payment service listens to orders.created, processes payments, and publishes results to orders.paid.
    • A shipping service listens to orders.paid and then sends messages to orders.shipped.
  • Why JetStream helps:
    • Streams store all these messages.
    • If the shipping service is down, when it comes back it can replay from where it left off.
    • Developers can also replay the entire stream later to audit how an order moved through the system.

2. IoT Sensor Data

  • Subjects:
    • sensors.building1.room23.temperature
    • sensors.building1.room23.humidity
    • sensors.building2.room10.temperature
  • Wildcard pattern:
    • sensors.*.*.temperature → Subscribe to all temperature data across all buildings and rooms.
    • sensors.building1.> → Subscribe to all sensor data in building1.
  • Why JetStream helps:
    • Billions of sensor events can be persisted.
    • Analytics services can replay old data for historical analysis.
    • If a dashboard service is offline, it doesn’t lose data — it just replays from the stream.

3. Audit Logging for Compliance

  • Subjects:
    • users.login
    • users.logout
    • users.failed_login
  • How it works:
    • Security services subscribe to all users.* events.
    • If there’s a breach, investigators can replay all login attempts using JetStream.
  • Why JetStream helps:
    • Keeps an immutable log of authentication events.
    • Developers can configure the stream to keep data for 90 days or more.

4. Microservices with Event Sourcing

  • Subjects:
    • inventory.item_added
    • inventory.item_removed
    • inventory.stock_adjusted
  • How it works:
    • Inventory changes are always stored as events.
    • A microservice can rebuild its state by replaying the event stream.
  • Why JetStream helps:
    • Reliable storage of all state changes.
    • Easy to recover service state after a crash.
See also  Scalability and Reliability in NATS

5. Multi-Tenant Applications

  • Subjects:
    • tenantA.payments.completed
    • tenantB.payments.completed
    • tenantC.payments.completed
  • Wildcard pattern:
    • *.payments.completed → Subscribe to all tenants.
    • tenantA.payments.* → Subscribe only to tenant A’s payment events.
  • Why JetStream helps:
    • Each tenant’s events can be separated logically but still stored in a single stream.
    • You can replay data per tenant for debugging or reporting.

Related posts:

Queue Groups in NATS: Load Balancing for Subscribers

Key-Value Store in NATS: Simple State Management

Request–Reply in NATS: One-to-One Messaging

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