durable-objects

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

Updated Dec 9, 2025
One-click install
npx skills add https://github.com/Aki2022/skills --skill durable-objects-aki2022
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/Aki2022/skills/tree/main/durable-objects
Command: npx skills add https://github.com/Aki2022/skills --skill durable-objects-aki2022

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @cloudflare/vitest-pool-workers, vitest, wrangler, zod, 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 semantics, 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 single-instance bottlenecks, misused blockConcurrencyWhile, and broken write coalescing. - Testing with Vitest: Set up @cloudflare/vitest-pool-workers for unit tests, integration tests via SELF, alarm triggering, and direct storage inspection. - Use Case: Build a multiplayer game backend where each match is a Durable Object with SQLite state, scheduled timeout alarms, and WebSocket connections, all tested in the Workers runtime. ## Quick Start Ask the assistant to create a Cloudflare Durable Object for a chat room with SQLite message storage, RPC methods, 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, 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.

Should I use RPC methods or fetch handlers in Durable Objects?

Use RPC methods with compatibility date 2024-04-03 or later. Public class methods become typed RPC endpoints callable directly on the stub, giving you type safety that a manual fetch handler does not provide.

When should I not use Durable Objects?

Avoid Durable Objects for stateless request handling, which plain Workers handle better, and for workloads needing maximum global distribution or high fan-out of independent requests. DOs excel at coordination, strong consistency, and per-entity state.

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 external fetch or I/O calls.

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 on schedule with automatic retries on failure, so handlers should be idempotent and can reschedule themselves for recurring work.