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
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-flagsnotbucket1 - Include purpose:
session-data,product-config
Optional description for the KeyValue store.
Time-to-live in nanoseconds. Keys expire after this duration. By default, keys do not expire.Common TTL values (in nanoseconds):
3600000000000- 1 hour86400000000000- 1 day604800000000000- 7 days2592000000000000- 30 days- No value - No expiration (permanent storage)
Number of historical values to keep per key. Default is 1, maximum is 64.
Maximum size in bytes of the KeyValue store. Default is -1 (unlimited).
Maximum size of a value in bytes. Default is -1 (unlimited).
Type of storage backend to use. Default is
file.Options:file- Persistent file storagememory- In-memory storage (faster but not persistent)
Number of replicas to keep in clustered bstream. Default is 1, maximum is 5.
Enable underlying stream compression to reduce storage size.
Optional bucket-specific metadata (custom key-value pairs).
Configure where the stream should be placed in a cluster.Properties:
cluster(string) - Target cluster nametags(array of strings) - Placement tags
Configuration for mirroring another KeyValue store.Properties:
name(string, required) - Name of the stream to mirrordomain(string) - Domain for cross-domain mirroringfilter_subject(string) - Subject filter for selective mirroringopt_start_seq(integer) - Starting sequence numberopt_start_time(integer) - Starting timestampsubject_transforms(array) - Subject transformation rules
Configure immediate republishing of messages after storage.Properties:
dest(string) - Destination subject patternsource(string) - Source subject pattern to matchheaders_only(boolean) - Only republish headers
Configure sources for the KeyValue store (for aggregating from multiple streams).Each source has:
name(string) - Name of source streamdomain(string) - Source domainfilter_subject(string) - Subject filteropt_start_seq(integer) - Starting sequenceopt_start_time(integer) - Starting timestampsubject_transforms(array) - Transformation rules
Response
Error Response
Example Usage
Common Use Cases
User Preferences
User Preferences
Store user settings and preferences with reasonable TTL
High-Speed Cache
High-Speed Cache
In-memory cache for frequently accessed data
Feature Flags
Feature Flags
Store feature toggles with history tracking
Session Data
Session Data
Temporary session storage with automatic expiration
kv-key-put
Add a new item or update an existing item in a Key-Value bucket.Parameters
Name of the bucket to store the item in. Bucket must exist.
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
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
Configuration Storage
Configuration Storage
Store application configuration
Rate Limiting
Rate Limiting
Track API usage per user
User State Management
User State Management
Maintain user state across sessions
Deduplication
Deduplication
Prevent duplicate processing
kv-key-get
Retrieve an item from a Key-Value bucket by its key.Parameters
Name of the bucket to retrieve from.
The key of the item to retrieve.
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 parsedfalse- When you stored a string or want the raw value
Response
Not Found Response
Example Usage
Common Patterns
Cache-Aside Pattern
Cache-Aside Pattern
Check cache before making expensive call
Load User Context
Load User Context
Load user data for personalization
Feature Flag Check
Feature Flag Check
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
Storage Monitoring
Storage Monitoring
Monitor storage usage and health
Admin Dashboard
Admin Dashboard
Build storage management interface
Audit and Compliance
Audit and Compliance
Track all storage buckets for compliance
kv-key-list
List all items (keys) contained within a Key-Value bucket.Parameters
Name of the bucket to list items from.
Sequence number to start listing from (for pagination). Use the sequence from the last item of the previous page.
Maximum number of items to return per request.
Response
Example Usage
Pagination Pattern
Common Patterns
Bulk Export
Bulk Export
Export all items for backup or migration
Data Cleanup
Data Cleanup
Find and remove old or unused items
Analytics
Analytics
Analyze stored data patterns
Search and Filter
Search and Filter
Find items matching criteria
Best Practices
Use Descriptive Keys
Include entity type in key:
user_123, session_abc, cache_product_456Set 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 dataHandle 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 availabilityPerformance Tips
Choose Right Storage Backend
Choose Right Storage Backend
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
Enable Compression for Large Values
Enable Compression for Large Values
Reduce storage size and network transfer
Use History for Versioning
Use History for Versioning
Track value changes over time
Set Max Value Size
Set Max Value Size
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
Bucket Names are Permanent: Bucket names cannot be changed after creation. Choose descriptive, meaningful names from the start.