DEV Community

Alex Spinov
Alex Spinov

Posted on

Deno KV Has a Free Database — Here's What Most Developers Don't Know

If you've been searching for a zero-config, globally distributed database that just works — Deno KV might be exactly what you need.

What is Deno KV?

Deno KV is a key-value database built directly into the Deno runtime. No setup, no connection strings, no external services. It's available everywhere Deno runs — locally and on Deno Deploy.

Getting Started (Zero Setup)

const kv = await Deno.openKv();

await kv.set(["users", "user_123"], {
  name: "Alice",
  email: "alice@example.com",
  createdAt: new Date(),
});

const result = await kv.get(["users", "user_123"]);
console.log(result.value);
Enter fullscreen mode Exit fullscreen mode

Key Features You Should Know

1. Hierarchical Keys

await kv.set(["posts", "2026", "march", "my-post"], { title: "Hello World" });

const posts = kv.list({ prefix: ["posts", "2026", "march"] });
for await (const entry of posts) {
  console.log(entry.key, entry.value);
}
Enter fullscreen mode Exit fullscreen mode

2. Atomic Transactions

const sender = await kv.get(["accounts", "alice"]);
const receiver = await kv.get(["accounts", "bob"]);

await kv.atomic()
  .check(sender)
  .check(receiver)
  .set(["accounts", "alice"], { balance: sender.value.balance - 100 })
  .set(["accounts", "bob"], { balance: receiver.value.balance + 100 })
  .commit();
Enter fullscreen mode Exit fullscreen mode

3. Watch for Real-Time Changes

const stream = kv.watch([["config", "theme"]]);
for await (const entries of stream) {
  console.log("Config changed:", entries[0].value);
}
Enter fullscreen mode Exit fullscreen mode

When to Use Deno KV

  • Session storage for web apps
  • Feature flags with real-time updates
  • Rate limiting with atomic counters
  • Caching with built-in TTL support
  • Simple CRUD apps without database overhead

Deno KV vs Alternatives

Feature Deno KV Redis SQLite
Setup Required None Server needed File setup
Global Distribution Built-in Manual No
Transactions Atomic ops MULTI/EXEC Full SQL
Real-time Watch Yes Pub/Sub No
Free Tier Generous Varies Free

Pricing on Deno Deploy

The free tier includes:

  • Unlimited reads (first 450,000/day unthrottled)
  • 300,000 write units/month
  • 1 GB storage

That's enough for most side projects and MVPs.

Real-World Example: URL Shortener in 30 Lines

import { serve } from "https://deno.land/std/http/server.ts";

const kv = await Deno.openKv();

serve(async (req: Request) => {
  const url = new URL(req.url);

  if (req.method === "POST") {
    const { slug, target } = await req.json();
    await kv.set(["urls", slug], target);
    return new Response(JSON.stringify({ short: `${url.origin}/${slug}` }));
  }

  const slug = url.pathname.slice(1);
  const result = await kv.get(["urls", slug]);

  if (result.value) {
    return Response.redirect(result.value as string, 302);
  }

  return new Response("Not found", { status: 404 });
});
Enter fullscreen mode Exit fullscreen mode

Need to scrape and store web data efficiently? Check out my web scraping actors on Apify Store — ready-to-use scrapers that deliver clean data in minutes. For custom scraping solutions, reach me at spinov001@gmail.com.

Top comments (0)