Skip to content

Storage: unstorage and Cloudflare KV

unstorage driver ecosystem (@xtandard/flags/storage/unstorage)

Section titled “unstorage driver ecosystem (@xtandard/flags/storage/unstorage)”

The unstorage adapter bridges any unstorage driver into FlagsStorage — so you get dozens of backends for free without a dedicated adapter:

Driver Use case
unstorage/drivers/upstash Upstash Redis (serverless / edge)
unstorage/drivers/vercel-kv Vercel KV
unstorage/drivers/cloudflare-kv-binding Cloudflare Workers KV
unstorage/drivers/s3 AWS S3 / R2
unstorage/drivers/github GitOps: read flags from a GitHub repo
unstorage/drivers/netlify-blobs Netlify Blobs
unstorage/drivers/fs / memory / redis filesystem / memory / Redis
import { createUnstorageStorage } from "@xtandard/flags/storage/unstorage";
import { createStorage } from "unstorage";
import upstash from "unstorage/drivers/upstash";
const storage = createUnstorageStorage({
storage: createStorage({
driver: upstash({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
}),
}),
});

A common production pattern: GitHub/file as source storage (GitOps, reviewable) and Upstash/Redis as runtime storage (fast edge reads).

Cloudflare Workers KV (@xtandard/flags/storage/cloudflare-kv)

Section titled “Cloudflare Workers KV (@xtandard/flags/storage/cloudflare-kv)”

Wraps a Workers KV namespace binding (env.MY_KV). No npm peer dependency — the binding is provided by the runtime, so the adapter only needs its structural type. Works in production Workers, in wrangler dev / Miniflare locally, and against any object satisfying the small KVNamespaceLike surface in tests.

import { createCloudflareKvStorage } from "@xtandard/flags/storage/cloudflare-kv";
export default {
async fetch(req: Request, env: { FLAGS: KVNamespace }) {
const storage = createCloudflareKvStorage({ namespace: env.FLAGS, prefix: "runtime" });
// mount the panel, or build an OpenFeature provider over `storage`
},
};

prefix namespaces every key (joined with :) and is stripped from getKeys, so several deployments can share one namespace. getKeys pages through KV’s cursor automatically. KV is eventually consistent — ideal for read-mostly compiled snapshots loaded once into memory; prefer Redis/libSQL for the write-heavy source store if you publish frequently from multiple regions.