NATS Key-Value & Object Store
Beginnerv1.0.0
Use NATS built-in Key-Value and Object stores — storing configuration, feature flags, state data, and binary objects with history, TTL, and watch capabilities from the NATS CLI.
Content
Overview
NATS KV and Object stores provide distributed storage built on JetStream. KV stores key-value pairs with history and watch. Object store handles large binary objects with chunking.
Why This Matters
- -Configuration — distributed config with real-time updates via watch
- -Feature flags — toggle features across services instantly
- -State management — share state between service instances
- -Object storage — store files and artifacts without external dependencies
How It Works
Step 1: Key-Value Store Basics
Step 2: History & Versioning
Step 3: Watch for Changes
Step 4: Object Store
Best Practices
- -Use KV for small values (under 1MB), Object store for larger data
- -Set --history on KV buckets for audit trail and rollback
- -Use watch for reactive configuration updates
- -Use TTL for cache-like data that should expire
- -Use dot-separated key names for wildcard watching
Common Mistakes
- -Storing large values in KV (use Object store instead)
- -No history on KV bucket (can't rollback bad config changes)
- -Not using watch (polling for changes is inefficient)
- -No max-bucket-size on Object store (unbounded growth)
- -Using KV as a general-purpose database (it's for config/state)
FAQ
Discussion
Loading comments...