KV, Deploy and deno compile
25. How does Deno KV work, and what are its limits?
Deno KV is a key-value store built into the runtime, opened with Deno.openKv(). Locally it uses SQLite, and on Deno Deploy it is backed by FoundationDB.
Keys are arrays of strings, numbers, bigints, booleans and byte arrays, ordered lexicographically, so ["user", id, "orders", orderId] lets kv.list({ prefix: ["user", id, "orders"] }) read one user's orders in order.
It still requires --unstable-kv (or "unstable": ["kv"] in config), per the KV docs.
Limits from the Deno.Kv API reference: keys up to 2,048 bytes and values up to 64 KiB after serialization, and list batches clamped at 500. Reads can be strong or eventual; writes are always strong.
There are no secondary indexes, so the application writes the same record under each key it needs to look it up by, inside one atomic operation.
26. Find the bug: a KV balance update.
const kv = await Deno.openKv();
export async function addCredit(userId: string, amount: number): Promise<void> {
const key = ["balance", userId];
const entry = await kv.get<number>(key);
await kv.set(key, (entry.value ?? 0) + amount);
}
Bug: a lost update. Two concurrent calls read the same balance, each adds its amount, and the second write overwrites the first. Nothing ties the write to the version that was read.
Fix: an atomic operation that checks the versionstamp and retries when the check fails.
export async function addCredit(userId: string, amount: number): Promise<void> {
const key = ["balance", userId];
while (true) {
const entry = await kv.get<number>(key);
const res = await kv.atomic()
.check(entry) // fails if the versionstamp changed since the read
.set(key, (entry.value ?? 0) + amount)
.commit();
if (res.ok) return;
}
}
A senior candidate offers the alternative for counters: store a Deno.KvU64 and use .sum(key, 1n), which needs no read.
They also bound the retry loop and note that a check against a null versionstamp asserts that the key does not exist, which is how you implement "create if absent".
27. How do KV queues work, and what delivery guarantee do they give?
kv.enqueue(value, options) schedules a message, and kv.listenQueue(handler) processes them; a handler that throws is retried.
Options include delay in milliseconds, a backoffSchedule, and keysIfUndelivered, the keys where the message is written if every retry fails.
Enqueue can also be part of an atomic operation, so a state change and its follow-up job commit together.
kv.listenQueue(async (msg: unknown) => {
const job = msg as { type: "welcome"; userId: string };
if (job.type === "welcome") await sendWelcomeEmail(job.userId);
});
await kv.atomic()
.set(["user", userId], user)
.enqueue({ type: "welcome", userId }, {
delay: 60_000,
keysIfUndelivered: [["failed_jobs", "welcome", userId]],
})
.commit();
Because failed handlers are retried, a message can run more than once; the handler must be idempotent, for example by recording a sent marker in KV and checking it first. A weak answer treats the queue as exactly-once.
28. What does deno compile produce, and what are the traps?
A single executable that bundles the denort runtime, your module graph and, by default, the whole resolved node_modules tree.
Per the compile reference, it cross-compiles to x86_64 and aarch64 targets for Linux, macOS and Windows from any host (Windows on ARM since 2.9.3), and permission flags are fixed at compile time.
deno compile \
--allow-net=api.example.com --allow-read=./data \
--include ./plugins \
--exclude-unused-npm \
--target x86_64-unknown-linux-gnu \
-o reportctl main.ts
The traps candidates should name:
- Dynamic imports that cannot be analyzed statically are left out; add them with
--include.
- Embedded files are read from a virtual file system at
import.meta.dirname; --self-extracting (2.7) writes them to disk on first run for libraries that need real paths, at the cost of a slower first start and modifiable files.
- Since 2.9,
localStorage and a Deno.openKv() call without a path persist in a per-app data directory; --app-name keeps that location stable across renames.
- macOS binaries get an ad-hoc signature; distribution outside your own machines still needs proper signing.
29. Find the bug: a compiled CLI with plugins.
// main.ts, built with: deno compile --allow-read=. -o tool main.ts
const name = Deno.args[0] ?? "default";
const plugin = await import(`./plugins/${name}.ts`);
await plugin.run();
Bug: the import specifier is built from a runtime value, so deno compile cannot see which plugin files to embed.
The binary works on the developer's machine, where ./plugins sits next to it under --allow-read=., and fails when shipped alone.
Fix: --include ./plugins at compile time, or a static map of plugin names to import() calls with literal specifiers, which also stops a user from passing ../../somewhere as a plugin name.
Version 2.9.8 also fixed compiled binaries to check read permission for dynamically imported local files, so a broad --allow-read=. is doing real work here and should be narrowed.
30. What is the state of Deno Deploy, and what would you do with an app running on it?
Two deadlines apply. Deno Deploy Classic (dash.deno.com) and the subhosting v1 API were scheduled to shut down on July 20, 2026, with apps moved by hand to the new Deno Deploy at console.deno.com, per the migration guide.
Then the October 9, 2026 Cloudflare announcement said Deno Deploy "will continue operating for six months before shutting down", with migration support for paying customers moving to Cloudflare Workers.
JSR keeps operating, with its infrastructure moving to Cloudflare.
A strong answer is a plan, not a lament:
- Inventory platform-specific APIs:
Deno.openKv() without a path, Deno.cron, KV queues, and any reliance on Deploy's environment contexts.
- Export KV data and pick a replacement store before the shutdown, because data does not move with the code.
- Keep handlers on web-standard
Request and Response, which port to Workers and other runtimes with the least change.
- Decide whether the app should also leave the Deno runtime, given the support window in question 31.