Key/Value Store | NATS Docs (original) (raw)

For the complete documentation index, see llms.txt. This page is also available as Markdown.

  1. NATS Concepts
  2. JetStream

Key/Value Store

JetStream, the persistence layer of NATS, not only allows for the higher qualities of service and features associated with 'streaming', but it also enables some functionalities not found in messaging systems.

One such feature is the Key/Value store functionality, which allows client applications to create buckets and use them as immediately (as opposed to eventually) consistent, persistent associative arrays (or maps). Note that this is an abstraction on top of the Stream functionality. Buckets are materialized as Streams (with a name starting with KV_), everything you can do with a bucket you can do with a Stream, but you ultimately have more functionality and flexibility and control when using the Stream functionality directly.

Do note, while we do guarantee immediate consistency when it comes to monotonic writes and monotonic reads. We don't guarantee read your writes at this time, as reads through direct get requests may be served by followers or mirrors. More consistent results can be achieved by sending get requests to the underlying stream leader of the Key/Value store.

Managing a Key Value store

  1. Create a bucket, which corresponds to a stream in the underlying storage. Define KV/Stream limits as appropriate

You can use KV buckets to perform the typical operations you would expect from an immediately consistent key/value store:

Atomic operations used for locking and concurrency control

You can set limits for your buckets, such as:

Treating the Key Value store as a message stream

Finally, you can even do things that typically can not be done with a Key/Value Store:

A valid key can contain the following characters: a-z, A-Z, 0-9, _, -, ., = and /, i.e. it can be a dot-separated list of tokens (which means that you can then use wildcards to match hierarchies of keys when watching a bucket). The value can be any byte array.

Last updated 8 months ago