

























We’re thrilled to introduce Deno KV, a strongly consistent key-value database, globally replicated for low-latency reads across 35 worldwide regions.
Deno Deploy aims to provide the simplest and fastest way to deploy and run JavaScript, TypeScript, and Wasm at the edge. However, creating stateful apps on Deno Deploy previously required connecting to external cloud databases, which involved additional configuration steps, local testing challenges, and potentially undermined the benefits of using the edge if the datastore wasn’t geographically replicated.
With today’s announcement, we’re bringing a globally integrated database to Deno that allows you to effortlessly develop full-featured apps while overcoming these obstacles.
In this post, we’ll discuss key aspects of Deno KV:
If you’re interested in using Deno KV, please join the waitlist.
Note: Deno KV is currently in beta, and long-term data durability is not
guaranteed. Please keep this in mind when using Deno KV for production
applications.
Note: Deno KV is currently in open beta.
Deno KV is seamlessly integrated into the open-source Deno runtime, allowing you to run it locally or deploy it as a managed service with zero configuration.
When running locally, Deno KV is backed by SQLite, providing a lightweight and easy-to-use solution for local development, testing, or for single region production systems.
When you deploy your application to Deno Deploy, the Deno KV database is automatically backed by FoundationDB. This managed solution is operated by the Deno company, ensuring high performance and reliability without the need for manual configuration or maintenance on your part.
Deno KV is a first-class primitive and exposes only a handful of methods that you can use to store, retrieve, delete, and enumerate data. Designed for JavaScript, Deno KV can store any JavaScript structured serializable value, such as Objects, Arrays, BigInts, Dates, and more.
const kv = await Deno.openKv(); const key = ["users", crypto.randomUUID()]; const value = { name: "Alice", created: new Date() }; await kv.set(key, value); const result = await kv.get(key); console.log(result.value);
Use the kv.list() operation to list all keys matching a specific selector. In
the example below, all keys starting with a particular prefix are selected.
await kv.set(["users", "alice"], { birthday: "January 1, 1990" }); await kv.set(["users", "sam"], { birthday: "February 14, 1985" }); await kv.set(["users", "taylor"], { birthday: "December 25, 1970" }); const iter = kv.list({ prefix: ["users"] }); for await (const entry of iter) { console.log(entry.key); console.log(entry.value); }
The list operation retrieves data from the store in batches, defaulting to 500
keys. To implement pagination, pass the iter.cursor property back into
subsequent calls of kv.list().
Learn more about the available methods in the documentation.
For many applications, reliable database transactions are necessary. This is
possible in Deno KV using kv.atomic() to create transactions with strong
consistency across multiple keys that are immediately durable by default:
const kv = await Deno.openKv(); const change = 10; const bob = await kv.get(["balance", "bob"]); const liz = await kv.get(["balance", "liz"]); if (bob.value < change) { throw "not enough balance"; } const success = await kv.atomic() .check(bob, liz) .set(["balance", "bob"], bob.value - change) .set(["balance", "liz"], liz.value + change) .commit();
Learn more about how we handle transactions.
Deno KV is a strongly-consistent database, providing external consistency, which includes:
You can relax consistency constraints with the consistency: "eventual" option
for individual read operations:
await db.get(["my-key"], { consistency: "eventual" }); await db.get(["my-key"], { consistency: "strong" });
This option allows the system to serve the read from global replicas and caches for minimal latency.
Here are average latency figures for the beta in our most popular regions. Improvements are expected for the public beta and GA release.
| Region | Latency (Eventual Consistency) | Latency (Strong Consistency) |
|---|---|---|
| North Virginia (us-east4) | 7ms | 7ms |
| Frankfurt (europe-west3) | 7ms | 94ms |
| Netherlands (europe-west4) | 13ms | 95ms |
| California (us-west2) | 72ms | 72ms |
| Hong Kong (asia-east2) | 42ms | 194ms |
Deno KV is a versatile solution for managing application state, making it ideal for various use cases. Here are some examples of applications showcasing the potential of Deno KV:
BroadcastChannel is used to help
synchronize state.As a basic example, explore this playground to see how simple it is to create a globally consistent, persistent counter using Deno KV:
import { serve } from "/std@0.155.0/http/server.ts"; const db = await Deno.openKv(); serve(async (req: Request) => { await db.atomic().sum(["views"], 1n).commit(); const res = await db.get(["views"]); const views = res.value.value; return new Response(`Views: ${views}`); });
Here are some more advanced demo apps we have built to illustrate Deno KV’s capabilities:
These examples provide a glimpse of what you can achieve with Deno KV. With its simplicity, scalability, and global replication, Deno KV is a powerful tool for developers looking to build stateful applications with ease.
Our mission is to make Deno Deploy the go-to platform for deploying and running API servers, web apps, and edge functions. Providing globally replicated, persistent data storage is a major step towards that goal. In the coming months, we’ll be introducing features to further simplify the process of building and deploying applications with just a few lines of code.
During the beta period, users can enjoy up to one gigabyte of storage for free. We will announce pricing details soon.
Other resources:
If you’re interested in using Deno KV, please join waitlist.
Don’t miss any updates — follow us on Twitter.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。