Skip to content

KV

deploybase KV is a key-value store for functions and server-rendered apps, stored in Paris in Scaleway object storage replicated across several availability zones. Code reaches it through the @deploybase/kv package (Node 22 or later). Store data with deploybase KV walks through using it.

KV is in beta on the Starter, Pro and Scale plans, with no price per request. The Free plan does not include it.

Import What it is
import { kv } from "@deploybase/kv" The store named default, configured by the platform. Works only in a deployed function or server-rendered app
import { createMemoryClient } from "@deploybase/kv/memory" A store whose data lives in the current process, for tests and your own machine. Each call returns an empty store
import { KVError } from "@deploybase/kv" The error class every failure that is not a usage mistake throws

createMemoryClient({ now }) takes an optional clock in milliseconds, so a test can expire keys without waiting.

Every store, kv and the memory client included, has these methods.

Method Returns
get(key, { type }) The value, or null when the key does not exist or has expired
getWithMetadata(key, { type }) { value, version, metadata, expiresAt }, or null. expiresAt is a Date, or null without a ttl. metadata is {} when none was set
set(key, value, options) { modified, version }. modified is false when a condition did not hold, and version is then absent
delete(key, { onlyIfVersion }) { modified }. Deleting a key that does not exist is not an error; it returns { modified: false }
list({ prefix, limit, cursor }) { keys, cursor, done }. Each key is { key, version, size, modifiedAt }. Pass cursor to the next call until done is true
store(name) Another named store, with the same methods
type You get
"json" (default) The parsed value. A value that is not JSON throws KV_NOT_JSON
"text" A string
"arrayBuffer" An ArrayBuffer
"stream" A ReadableStream of bytes

An ArrayBuffer, a typed array or a Buffer is stored as bytes. Any other value is stored as JSON. undefined cannot be stored.

Option of set Effect
ttl Seconds until the key expires: whole seconds, at least 60
onlyIfNew Write only if the key does not exist or has expired
onlyIfVersion Write only if the key is at this version
metadata A plain JSON object stored with the value, read back by getWithMetadata

onlyIfNew and onlyIfVersion cannot be combined. Every set replaces the whole entry: a set without ttl stores a key that never expires, and one without metadata clears the metadata an earlier write gave it.

Every write returns a version: an opaque string that changes when the stored bytes of the value change. It depends on the value only: a write that changes just the ttl or the metadata keeps the version. Pass it as onlyIfVersion to set or delete to act only if nobody changed the key since you read it. A missing key matches no version.

  • A get that starts after a set or delete has returned sees that write, from any function or request.
  • Each call acts on one key. There are no transactions across keys: to change two keys together, keep them in one value.
  • Do not rely on the order of the keys list returns.
Rule
Store name 1 to 64 characters of a-z, 0-9 and -. kv is the store named default
Environments Production and preview data are separate. Functions in functions/ and the production deployment of a server-rendered app use production data. Every branch preview of a server-rendered app uses the project’s one preview data set
Scope One project. A project never sees another project’s data

A condition that does not hold is a result, not an error: get returns null, and set and delete return { modified: false }. A wrong argument, such as an empty key or a ttl under 60, throws a TypeError before anything is sent. Everything else throws a KVError with code, status (when the service answered) and requestId. Quote the requestId when you contact support.

Status Code Meaning Retried by the client
KV_NOT_AVAILABLE kv was used outside a deployed function, or the team does not have KV No
KV_TIMEOUT No answer in time: 2 seconds, or 5 seconds for a value over 100 KB Yes
KV_NETWORK_ERROR The service could not be reached, or the answer was cut off Yes
KV_NOT_JSON get with type json on a value that is not JSON No
400 KV_INVALID_KEY, KV_INVALID_STORE, KV_INVALID_REQUEST The key, store name or an option is not valid No
401 KV_UNAUTHORIZED, KV_TOKEN_REVOKED The function’s access was withdrawn, for example because the project is being deleted or the team is suspended No
402 KV_STORAGE_LIMIT_EXCEEDED The team is over its storage limit. Delete keys to write again No
413 KV_VALUE_TOO_LARGE The value is over 1 MB No
429 KV_RATE_LIMITED Too many requests at once for your team Yes, after 1 s
503 KV_BUSY The service is under load Yes, after 1 s
503 KV_STORAGE_MEASURING The team’s storage is being measured before a write near the limit Yes, after 5 s
503 KV_REVOCATIONS_STALE A write was held back while the service refreshes which access was withdrawn Yes, after 5 s
503 KV_STORAGE_UNAVAILABLE Storage did not answer Yes, after about 250 ms
500 KV_INTERNAL_ERROR A fault on our side No

The client retries at most twice, and waits for the service’s Retry-After when it sends one, up to 5 seconds. Every write keeps one id across its attempts, so a retried write that already landed is not applied twice, and an onlyIfNew write does not report its own earlier attempt as a conflict.

One call takes at most about 16 seconds with its retries (three attempts of 2 seconds and two waits of up to 5), or 25 seconds for a value over 100 KB. Keep that inside your function’s timeout, or catch the error sooner with your own deadline.

If the service or its storage is down for longer than the retries cover, every call throws a KVError with KV_TIMEOUT, KV_NETWORK_ERROR, KV_STORAGE_UNAVAILABLE or KV_BUSY. Catch it and answer with a 503 or a fallback, such as a cached copy, rather than letting the request fail with an unhandled error.

A set or delete that ends in KV_TIMEOUT, KV_NETWORK_ERROR or KV_INTERNAL_ERROR may or may not have been applied. To retry it safely:

  • For a new key, call set again with onlyIfNew. { modified: false } then means a write already exists: read it to see whether it is yours.
  • For an update, read the key with getWithMetadata and write again with onlyIfVersion. If the value is already what you meant to write, the first write landed.
  • A plain set of the same value is safe to repeat. A plain set that depends on the old value, like count + 1, is not.
Limit Value
Storage per team 1 GB during the beta, every project and both environments together
Value 1 MB
Metadata 1 KB, as JSON
Key 1 to 256 bytes of UTF-8
Shortest ttl 60 seconds
Longest ttl 100 years
Keys per list page 100 by default, at most 1000 (limit)
Requests Plan for 200 per second per team, with at most 16 in progress at once. Over that you get KV_RATE_LIMITED, which the client retries

There is no price per request. Limits per plan are set when the beta ends.

  • The storage limit is approximate. Usage is estimated between measurements, so a team can pass 1 GB by a little before writes are refused. A team is only refused after a measurement shows it is over.
  • list can show an expired key for up to 5 minutes. get never returns it: expiry is checked on every read, and expired keys are cleared every 5 minutes.
  • Identical bytes give the same version. If a key is written with value A, then B, then A again, its version is the same as after the first write, so an onlyIfVersion taken at the first A still matches. Keep a counter or a timestamp in the value if that matters to you.
  • A deleted or overwritten value cannot be restored. There are no backups and no earlier versions. Replication across availability zones protects against a failed disk or zone, not against a delete.
  • Only deployed code can use kv. On your own machine and in tests, use @deploybase/kv/memory. KV is not available in the build step.
  • A function gets access within about 10 minutes of its team getting KV, or at once on its next production deploy.

Each key records who last wrote it: a team member, an AI agent a team member connected to their own account, an API key or a function. Changes made from the dashboard, by such an agent or with an API key are kept for 90 days: who, when and which key, never the value. Writes by functions only update the key’s last writer. Old values are never kept.

KV data is stored in Paris by Scaleway, a sub-processor already listed for the rest of the platform. When you delete a project, its KV data is deleted within 24 hours; deleting your team deletes all of it. Our DPA covers the personal data your functions and your team write to KV.

Live 582ac705 built