Skip to main content

Key-Value Storage Functions

Key-Value (KV) storage provides fast, simple data storage with key-based access. Perfect for configuration, caching, state management, and session storage.
What is Key-Value Storage? KV storage is a simple database where you store data with a unique key and retrieve it later using that key. Think of it like a dictionary or hash map that persists across flow executions.

Function List

kv-bucket-create

Create a new KV bucket

kv-key-put

Add or update an item

kv-key-get

Retrieve an item by key

kv-bucket-list

List all KV buckets

kv-key-list

List items in a bucket

kv-bucket-create

Create a new Key-Value storage bucket. Buckets are containers for related key-value pairs with configurable storage options, replication, and TTL settings.

Parameters

bucket
string
required
Name of the bucket to create. Must be unique and can only contain alphanumeric characters, dashes, and underscores.Naming conventions:
  • Use lowercase with hyphens: user-preferences, api-cache
  • Be descriptive: feature-flags not bucket1
  • Include purpose: session-data, product-config
description
string
Optional description for the KeyValue store.
ttl
integer
Time-to-live in nanoseconds. Keys expire after this duration. By default, keys do not expire.Common TTL values (in nanoseconds):
  • 3600000000000 - 1 hour
  • 86400000000000 - 1 day
  • 604800000000000 - 7 days
  • 2592000000000000 - 30 days
  • No value - No expiration (permanent storage)
history
integer
Number of historical values to keep per key. Default is 1, maximum is 64.
max_bytes
integer
Maximum size in bytes of the KeyValue store. Default is -1 (unlimited).
max_value_size
integer
Maximum size of a value in bytes. Default is -1 (unlimited).
storage
string
Type of storage backend to use. Default is file.Options:
  • file - Persistent file storage
  • memory - In-memory storage (faster but not persistent)
num_replicas
integer
Number of replicas to keep in clustered bstream. Default is 1, maximum is 5.
compression
boolean
Enable underlying stream compression to reduce storage size.
metadata
object
Optional bucket-specific metadata (custom key-value pairs).
placement
object
Configure where the stream should be placed in a cluster.Properties:
  • cluster (string) - Target cluster name
  • tags (array of strings) - Placement tags
mirror
object
Configuration for mirroring another KeyValue store.Properties:
  • name (string, required) - Name of the stream to mirror
  • domain (string) - Domain for cross-domain mirroring
  • filter_subject (string) - Subject filter for selective mirroring
  • opt_start_seq (integer) - Starting sequence number
  • opt_start_time (integer) - Starting timestamp
  • subject_transforms (array) - Subject transformation rules
republish
object
Configure immediate republishing of messages after storage.Properties:
  • dest (string) - Destination subject pattern
  • source (string) - Source subject pattern to match
  • headers_only (boolean) - Only republish headers
sources
array
Configure sources for the KeyValue store (for aggregating from multiple streams).Each source has:
  • name (string) - Name of source stream
  • domain (string) - Source domain
  • filter_subject (string) - Subject filter
  • opt_start_seq (integer) - Starting sequence
  • opt_start_time (integer) - Starting timestamp
  • subject_transforms (array) - Transformation rules

Response

Error Response

Example Usage

Common Use Cases

Store user settings and preferences with reasonable TTL
In-memory cache for frequently accessed data
Store feature toggles with history tracking
Temporary session storage with automatic expiration

kv-key-put

Add a new item or update an existing item in a Key-Value bucket.

Parameters

bucket
string
required
Name of the bucket to store the item in. Bucket must exist.
key
string
required
Unique key for the item. If key exists, the value will be updated.Key strategies:
  • User data: user_${userId} - e.g., user_123
  • Session data: session_${sessionId} - e.g., session_abc
  • Cache keys: cache_${resource}_${id} - e.g., cache_product_456
  • Config: Descriptive names - e.g., max_retries, api_timeout
value
string | object
required
The value to store. Can be a string or an object that will be JSON-serialized.Value types:
  • String: "Hello World"
  • Object: {"name": "John", "age": 30}
  • Array: [1, 2, 3, 4] (as object)
  • Number/Boolean: Must be wrapped in object or converted to string

Response

Error Response

Example Usage

Common Patterns

Store application configuration
Track API usage per user
Maintain user state across sessions
Prevent duplicate processing

kv-key-get

Retrieve an item from a Key-Value bucket by its key.

Parameters

bucket
string
required
Name of the bucket to retrieve from.
key
string
required
The key of the item to retrieve.
json
boolean
required
Whether to parse the value as JSON. Set to true to parse objects, false to get raw string.When to use:
  • true - When you stored an object and want it parsed
  • false - When you stored a string or want the raw value

Response

Not Found Response

Example Usage

Common Patterns

Check cache before making expensive call
Load user data for personalization
Check if feature is enabled

kv-bucket-list

List all Key-Value storage buckets in your account with their metadata.

Parameters

This function takes no input parameters. It returns all buckets in your account.

Response

Example Usage

Common Use Cases

Monitor storage usage and health
Build storage management interface
Track all storage buckets for compliance

kv-key-list

List all items (keys) contained within a Key-Value bucket.

Parameters

bucket
string
required
Name of the bucket to list items from.
last_sequence
integer
Sequence number to start listing from (for pagination). Use the sequence from the last item of the previous page.
limit
integer
Maximum number of items to return per request.

Response

Note: The value field in list results is always returned as a string. You’ll need to parse JSON values manually if needed.

Example Usage

Pagination Pattern

Common Patterns

Export all items for backup or migration
Find and remove old or unused items
Analyze stored data patterns
Find items matching criteria

Best Practices

Use Descriptive Keys

Include entity type in key: user_123, session_abc, cache_product_456

Set Appropriate TTLs

Configure TTL at bucket creation. Remember: TTL is in nanoseconds!

Choose Right Storage Type

Use memory for high-speed cache, file for persistent data

Handle Status Codes

Always check status_code in responses (200 = success, 404 = not found)

Parse JSON Carefully

Use json: true in kv-key-get for objects. List results are always strings.

Plan for Replication

Use num_replicas for critical data to ensure high availability

Performance Tips

Match storage type to use case
  • ✅ Memory storage: High-speed cache, temporary data
  • ✅ File storage: Persistent data, long-term storage
  • ❌ Memory storage: Critical data that must survive restarts
Reduce storage size and network transfer
Track value changes over time
Prevent oversized values from consuming resources

Example Workflows

User Preference Management

1

Create Bucket

2

Store Preferences

3

Load on Login

API Response Caching

1

Create Cache Bucket

2

Check Cache

3

Cache Miss - Store Response

Feature Flag System

1

Create Flags Bucket

2

Set Feature Flag

3

Check in Flow


Important Notes

TTL is in Nanoseconds: When setting TTL, remember that the value must be in nanoseconds, not seconds. 1 hour = 3,600,000,000,000 nanoseconds.
JSON Parsing: The json parameter in kv-key-get is required. Set it to true to parse object values, false for strings.
List Values are Strings: When using kv-key-list, all values are returned as strings. You must parse JSON values manually.
Bucket Names are Permanent: Bucket names cannot be changed after creation. Choose descriptive, meaningful names from the start.

Next Steps

Stream Functions

Real-time event processing

Object Storage

Store large files and documents

Data Transformation

Transform and encode data

Functions Step

Using Functions in flows