durable-objects

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

Updated Oct 15, 2019
One-click install
npx skills add https://github.com/kkkaoru/dotfiles --skill durable-objects-kkkaoru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/kkkaoru/dotfiles/tree/main/.agents/skills-stroage/durable-objects
Command: npx skills add https://github.com/kkkaoru/dotfiles --skill durable-objects-kkkaoru

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 correct Durable Object patterns for sharding, storage, concurrency, and alarms, and outdated knowledge of the API leads to subtle bugs and anti-patterns. ## Core Features & Use Cases - Durable Object Implementation: Create DO classes with RPC methods, SQLite storage, alarms, and WebSocket hibernation following current best practices. - Code Review: Audit existing DO code for anti-patterns like global singletons, misused blockConcurrencyWhile, and broken write coalescing. - Configuration & Testing: Set up wrangler bindings and migrations, plus unit and integration tests with @cloudflare/vitest-pool-workers. - Use Case: Build a multiplayer chat application where each room is a Durable Object with SQLite-backed message history, WebSocket connections, and an alarm that archives inactive rooms. ## Quick Start Use the durable-objects skill to create a chat room Durable Object with SQLite storage and WebSocket support, including wrangler config and Vitest tests.

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 and this.ctx.storage.sql.exec for synchronous SQL queries.

How do I test Durable Objects with Vitest?

Use @cloudflare/vitest-pool-workers to run tests inside the Workers runtime. Access stubs via env from cloudflare:test, inspect internals with runInDurableObject, and trigger alarms immediately with runDurableObjectAlarm.

When should I use Durable Objects instead of 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. Plain Workers are better for stateless request handling and maximum global distribution.

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.

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 initialization and never hold it across fetch or external I/O.

How do Durable Object alarms work?

Each Durable Object supports one alarm at a time, and calling setAlarm replaces any existing alarm. The alarm handler runs at the scheduled time with automatic retries on failure, so handlers should be idempotent and can reschedule themselves.