durable-objects

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

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/leonardoacosta/agents --skill durable-objects-leonardoacosta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/leonardoacosta/agents/tree/main/skills/durable-objects
Command: npx skills add https://github.com/leonardoacosta/agents --skill durable-objects-leonardoacosta

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 use of Durable Objects APIs, SQLite storage, concurrency rules, and wrangler configuration, where mistakes like global bottlenecks or lost in-memory state are common. ## Core Features & Use Cases - Durable Object Implementation: Guidance for creating DO classes with RPC methods, SQLite storage, schema migrations, alarms, and WebSocket hibernation. - Code Review & Anti-Patterns: Rules for sharding, concurrency gates, write coalescing, and avoiding single global DO bottlenecks. - Testing & Workers Integration: Vitest setup with @cloudflare/vitest-pool-workers, alarm testing, wrangler configuration, and Worker handler patterns. - Use Case: Build a chat room application where each room is a Durable Object with persistent message history in SQLite, real-time WebSocket broadcast, and a scheduled alarm for cleanup. ## Quick Start Use the durable-objects skill to create a chat room Durable Object with SQLite storage and wire it up in wrangler.jsonc.

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 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 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 are designed for coordination and strong consistency per entity.

Why does my Durable Object lose state between requests?

Class properties are lost when the instance is evicted or crashes. Always persist critical state to SQLite storage first, then update in-memory caches, since only storage survives eviction.

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 DO supports one alarm at a time, and calling setAlarm replaces any existing alarm. Implement an async alarm() handler that processes scheduled work and optionally reschedules; failed alarms retry automatically, so handlers should be idempotent.