Run it
Operations
Deploy, configure, create databases with a placement, sign in to the dashboard, drive the bench API, and upgrade without breaking running shards.
Deploy
npx wrangler secret put VALKEY_PASSWORD
npx wrangler secret put BENCH_TOKEN # optional: turns on the bench API
npm run deploy -- --var ACCESS_TEAM_DOMAIN:https://<team>.cloudflareaccess.com --var ACCESS_AUD:<tag>
VADO_REDIS=1 npm run deploy # carry the Redis flavour tooOpen connections keep the old router code until they end. Busy shards restart onto the new code within about 30 s without failing commands, and idle ones get it when they next start. Wait a minute after a deploy before measuring anything.
Settings
| Setting | Default | Meaning |
|---|---|---|
| VALKEY_PASSWORD (secret) | unset | Makes AUTH mandatory and turns on /ws |
| BENCH_TOKEN (secret) | unset | Bearer token for the bench API; unset turns it off |
| ACCESS_TEAM_DOMAIN, ACCESS_AUD | required | Dashboard sign-in with Cloudflare Access |
| SHARD_EPOCHS | [{"from":0,"shards":1}] | Shard count by creation time. Append, never edit |
| LOCATION_HINT | unset | Region for new shards without a regions list, and every pub/sub shard |
| VALKEY_MAXMEMORY | 64mb | Per shard. Keep it at or under 64 MB: the memory limit is 128 MB |
| VALKEY_MAXMEMORY_POLICY | noeviction | allkeys-lru for a cache |
| VALKEY_LOGLEVEL | warning | Valkey's log level, written to the Worker's logs |
| ROUTER_IDLE_MS | 30000 | Idle shard sockets close after this |
| ROUTER_SOCKET_BUDGET | 128 | Sockets per process before routers switch to batched calls |
Create a database with a placement
Databases are created on first use with the current epoch's shard count, at LOCATION_HINT. To choose the size, placement, replicas or flavour, create it first, through the bench API or the dashboard's New database dialog:
curl -H "authorization: Bearer $TOKEN" \
"https://<your-worker>.workers.dev/db?db=mydb&shards=16®ions=world&replicas=world"regions and replicas take world or a comma-separated list of hints. flavour=redis runs Redis, and password=new gives the database its own password, returned once. For an existing database, /db returns its record unchanged.
Dashboard sign-in
The dashboard is the Worker's own URL. Anyone can watch: live numbers come over /live from the database's Watcher, and carry counts, sizes, rates and city names, never keys, values or client addresses.
Changes need signing in through the Access application on /signin (setup). Every change verifies the Access token against the team's signing keys, ACCESS_TEAM_DOMAIN as issuer and ACCESS_AUD as audience, before it runs. Signed in, you can create databases, run a command and see which shard and replica answered, restart a shard, and start test traffic, which stops by itself after 10 minutes. The dashboard refuses KEYS, FLUSHALL and FLUSHDB; those belong in a client.
The bench API
https://<your-worker>.workers.dev/<test>?... with Authorization: Bearer <BENCH_TOKEN>. Every test takes db (default default), and via=shard&shard=<i> to skip the router.
| Test | What it does |
|---|---|
| db | Create a database, or return its record: shards, regions, replicas, flavour, password=new |
| stats, shards | Each shard's host stats, files and replica states; shards adds Valkey's INFO |
| throughput | Pipelined SETs (op=get reads them back) over conns connections: n, batch, value, keys |
| latency | One PING, then n GETs one at a time: first reply, p50, p99 and max |
| run | The commands in a POSTed JSON array, such as [["SET","k","v"],["GET","k"]] |
| send | Run another test from a Sender object in region, so load starts where you choose |
| durability, write, verify | Write known keys, abort every shard (or deploy in between), read them back |
| abort | Hard-reset one shard, all of them, or one region's replicas |
| staleness, ryw | Replica lag seen by a second connection; stale reads on one connection |
| commit | How long shard 0's storage takes to confirm a write, from inside the object |
| rewrite | BGREWRITEAOF on shard 0 while another connection PINGs it |
| fill, frag | Write until OOM; measure fragmentation of wasm memory against used_memory |
| churn | n connections, par at a time, each AUTH, SET, GET and close |
| drop | Drop a database for good. Its name is never reused and its shards keep only a tombstone |
Upgrading safely
- During a deploy, old routers call new shards, old primaries stream to new replicas, and old shards send rewrites to new rewriters. Keep Durable Object methods and the rewriter's socket protocol stable, and make changes additive.
- Each object's tables come from its
migrations.ts. Add a migration; never edit a shipped one or rename a table or column. - New Durable Object classes need a new migration tag in the Worker's wrangler.jsonc.
- Never remove a shard class, and keep rewriter classes in step with shard classes: class
kfindsREWRITER<k>by name. - Don't roll back past the change that added shard classes, or the one that stored file rows under keys. Older code can't find the shards or read the files written since.
- Change capacity by appending an epoch. Existing databases keep their size.