KV Store
KV Store is a distributed key-value storage service that runs across Azion's network, providing low-latency data persistence and retrieval.
Preview
KV Store is a distributed key-value storage service that runs across Azion’s network. It lets you persist and retrieve small pieces of data with very low latency from anywhere your users are, without managing servers.
The JavaScript API is designed to be compatible with the Cloudflare Workers KV API, making it easier to migrate existing applications to Azion’s platform.
Typical use cases include:
- Session and authentication tokens
- Feature flags and A/B testing configurations
- User preferences and personalization
- Caching API responses and computed fragments
- Rate-limit counters and idempotency keys
- Shopping cart or draft state
How it works
KV Store organizes data into namespaces, where each namespace contains an independent set of keys. Here’s how the system operates:
- Data is organized into namespaces that contain independent sets of keys.
- Each item is addressed by a key that is unique within its namespace.
- Values can be stored as text, JSON, ArrayBuffer, or ReadableStream.
- Data is replicated across global points of presence to maximize availability and read performance.
- Single-key operations are atomic per key. Multi-key transactions aren’t supported.
Implementation resources
| Scope | Resource |
|---|---|
| Manage KV Store with Functions | How to manage KV Store with Functions |
| KV Store API reference | Azion API - KV Store |
Data resilience
KV Store uses a distributed architecture with replication across Azion nodes. New writes are accepted and propagated to replicas to ensure durability and high availability. Reads are served from the closest healthy replica to minimize latency.
Namespaces
A namespace is an isolated key space. Use namespaces to segment data by application, environment, or workload.
Recommended patterns
- Use separate namespaces for production and staging environments.
- Prefix keys to model hierarchy, for example:
users/123/profile,flags/new-ui,carts/region-br/user-42. - Keep keys short and meaningful; prefer a few path-like segments over long opaque identifiers.
Naming conventions
- Names must be unique within your account.
- Names must be between 3 and 63 characters.
- Use lowercase letters, numbers, dashes, and underscores.
- Names must match the pattern:
^[a-zA-Z0-9_-]+$
Managing namespaces via API
You can manage namespaces using the Azion API. The base endpoint is:
Create a namespace
Response (201 Created):
List namespaces
Query parameters:
| Parameter | Type | Description |
|---|---|---|
fields | string | Comma-separated list of field names to include in the response |
page | integer | Page number within the paginated result set |
page_size | integer | Number of items per page |
Retrieve a namespace
Interacting with KV Store via Functions
You can interact with KV Store directly from your functions using the
Azion.KV class. The examples below illustrate common patterns for creating,
reading, updating, and deleting data.
Initializing the KV client
You can initialize the KV client using the constructor or the open method:
Storing data (put)
Store values in different formats:
Storing large data with streams
For large payloads, use ReadableStream to stream data efficiently:
Retrieving data (get)
Retrieve values in different formats:
Retrieving multiple keys
Retrieve multiple values in a single operation:
Retrieving data with metadata
Use getWithMetadata to retrieve both the value and its associated metadata:
Reading streams
Process streamed data incrementally:
Deleting data
Remove a key from the store:
Working with Unicode and special characters
KV Store supports UTF-8 and UTF-16 encoded keys and values:
Deleting namespaces
Delete an entire namespace programmatically:
Methods reference
The Azion.KV class provides the following methods:
Constructor and initialization
| Method | Description |
|---|---|
new Azion.KV() | Creates a KV instance using the default namespace |
new Azion.KV(name) | Creates a KV instance for the specified namespace |
Azion.KV.open(name) | Opens a namespace asynchronously |
Azion.KV.delete(name) | Deletes a namespace |
Data operations
| Method | Parameters | Returns | Description |
|---|---|---|---|
put(key, value, options?) | key: stringvalue: string | object | ArrayBuffer | ReadableStreamoptions: { metadata?, expiration?, expirationTtl? } | Promise<void> | Stores a value |
get(key, type?, options?) | key: string | string[]type: “text” | “json” | “arrayBuffer” | “stream”options: { cacheTtl? } | Promise<value | null> | Retrieves a value |
getWithMetadata(key, type?, options?) | key: string | string[]type: “text” | “json” | “arrayBuffer” | “stream”options: { cacheTtl? } | Promise<{'{value, metadata}'}> | Retrieves value with metadata |
delete(key) | key: string | Promise<void> | Deletes a key |
Put options
| Option | Type | Description |
|---|---|---|
metadata | object | Custom metadata to associate with the key (max 1024 bytes JSON-serialized) |
expiration | number | Unix timestamp (seconds) when the key expires |
expirationTtl | number | Time-to-live in seconds from now |
Get options
| Option | Type | Description |
|---|---|---|
cacheTtl | number | Time in seconds to cache the result locally (minimum 60 seconds) |
Get types
| Type | Returns | Description |
|---|---|---|
"text" | string | Returns the value as a UTF-8 string (default) |
"json" | object | Parses the value as JSON |
"arrayBuffer" | ArrayBuffer | Returns raw binary data |
"stream" | ReadableStream | Returns a readable stream for large values |
Limits
These are the default limits:
| Limit | Value |
|---|---|
| Per-key write rate | Up to 1 write per second to the same key |
| Key size | Up to 512 bytes (UTF-8) |
| Metadata size | Up to 1024 bytes (JSON-serialized) |
| Value size | Up to 25 MB per item |
| Namespace name length | 3-63 characters |
Minimum expirationTtl | 60 seconds |
Minimum cacheTtl | 60 seconds |
These are the default limits for each Service Plan:
| Scope | Developer | Business | Enterprise | Mission Critical |
|---|---|---|---|---|
| Namespaces | 1000 | 1000 | 1000 | 1000 |
| Maximum file size | 200 MB | 500 MB | 2 GB | 2 GB |
| Maximum storage per account | 5 GB | 50 GB | 300 GB | 300 GB |
Limitations
The following operations are not supported:
- List keys: There is no
list()method to enumerate keys within a namespace. Design your application to track keys externally if needed. - Multi-key transactions: Operations are atomic per key, but there is no support for transactions spanning multiple keys.
- Namespace management from functions: Namespaces must be created and managed via the Azion API or Console, not from within functions.