durable-objects

Create and review Cloudflare Durable Objects for stateful coordination, RPC, SQLite storage, alarms, and WebSockets.

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill durable-objects-mintuz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/durable-objects
Command: npx skills add https://github.com/mintuz/.dotfiles --skill durable-objects-mintuz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @cloudflare/vitest-pool-workers, vitest, wrangler, and includes references (resource) components.

What problem does it solve? Building stateful, coordinated applications on Cloudflare's edge requires deep knowledge of Durable Objects APIs, concurrency rules, storage patterns, and wrangler configuration, and outdated knowledge leads to subtle bugs like race conditions, lost state, and throughput bottlenecks. ## Core Features & Use Cases - Durable Object Implementation: Create DO classes with RPC methods, SQLite storage, schema migrations, alarms, and WebSocket hibernation following current best practices. - Code Review & Anti-Pattern Detection: Review existing DO code for issues like global singleton bottlenecks, misused blockConcurrencyWhile, and unpersisted in-memory state. - Testing with Vitest: Set up unit, integration, alarm, and storage tests using @cloudflare/vitest-pool-workers with isolated per-test state. - Use Case: Build a multiplayer chat application where each chat room is a Durable Object with SQLite-backed message history, WebSocket connections, and an alarm that archives inactive rooms. ## Quick Start Create a Cloudflare Durable Object for a chat room with SQLite storage, RPC methods, and the required wrangler configuration.

Frequently Asked Questions about durable-objects

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Cloudflare Durable Object with SQLite storage?

Extend the DurableObject class from cloudflare:workers and configure new_sqlite_classes in your wrangler migrations. Initialize tables inside the constructor using ctx.blockConcurrencyWhile, then run synchronous queries via this.ctx.storage.sql.exec.

How do I test Durable Objects with Vitest?

Use @cloudflare/vitest-pool-workers with defineWorkersConfig pointing at your wrangler config. Access stubs via env from cloudflare:test, inspect internals with runInDurableObject, and trigger alarms instantly with runDurableObjectAlarm.

When should I use Durable Objects versus plain Workers?

Use Durable Objects when you need coordination, strong consistency, per-entity storage, or persistent WebSocket connections, such as chat rooms or booking systems. Use plain Workers for stateless request handling or high fan-out independent requests.

Why does blockConcurrencyWhile hurt Durable Object performance?

blockConcurrencyWhile blocks all concurrency in the instance, so using it on every request caps throughput at roughly 200 requests per second. Reserve it for one-time constructor initialization and never hold it across fetch or external I/O.

Does Durable Objects SQLite support PRAGMA user_version for migrations?

No, PRAGMA user_version is not supported in Durable Objects SQLite storage. Track schema versions in a dedicated _sql_schema_migrations table and apply incremental migrations during constructor initialization.

How do Durable Object alarms work?

Each Durable Object supports one alarm at a time, and calling setAlarm replaces any existing alarm. Implement an async alarm() handler to process scheduled work, optionally rescheduling by calling setAlarm again, and keep handlers idempotent since failed alarms auto-retry.