durable-objects

Implement stateful coordination with Cloudflare Durable Objects using SQLite storage and RPC methods.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Durable Objects provide a consistent, low-latency way to manage per-entity state and coordination at the Cloudflare edge, eliminating race conditions and complexity when building chat rooms, multiplayer sessions, booking systems, and other stateful features that require strong consistency.

Core Features & Use Cases

  • Deterministic routing: Use getByName or idFromName to ensure the same input maps to the same DO instance for chat rooms, game sessions, or tenant-scoped state.
  • Durable storage & migrations: Prefer SQLite storage with migrations (new_sqlite_classes) for durable per-entity data and schema evolution.
  • Safe initialization & concurrency: Initialize schema and migrations inside blockConcurrencyWhile in the constructor and avoid holding it during external I/O.
  • RPC, alarms & WebSockets: Implement typed RPC methods for direct calls, use setAlarm/deleteAlarm for scheduled work, and accept WebSocket connections for persistent streams.
  • Testing & tooling: Configure wrangler and use @cloudflare/vitest-pool-workers for unit and integration tests, run alarms with runDurableObjectAlarm, and verify storage with runInDurableObject. Use cases include chat room message coordination, per-tenant counters and quotas, turn-based game match state, and scheduled cleanup or billing tasks.

Quick Start

Create a Durable Object class for a chat room that uses SQLite for persistent messages, exposes RPC methods sendMessage and getMessages, initializes its schema with blockConcurrencyWhile, and includes a Vitest test that verifies isolation between instances.

Frequently Asked Questions about durable-objects

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

FAQPage Schema
How do I manage stateful coordination for WebSocket chat rooms in Cloudflare Workers?

Stateful coordination for WebSocket chat rooms in Cloudflare Workers is managed using Durable Objects to handle per-entity state and concurrency. They provide consistent, low-latency routing and eliminate race conditions by ensuring the same input maps to the same instance.

How do I initialize SQLite schema and migrations safely in a Durable Object?

Initialize SQLite schema and migrations safely inside the blockConcurrencyWhile method in the Durable Object constructor. This ensures safe initialization by blocking concurrent requests, but you must avoid holding it during external I/O operations.

Does Cloudflare Durable Objects support scheduled alarm-driven tasks?

Cloudflare Durable Objects support scheduled alarm-driven tasks using setAlarm and deleteAlarm semantics. This allows you to implement scheduled cleanup, billing tasks, or turn-based game match state effectively at the edge.

How do I test Durable Objects isolation and alarm scheduling with Vitest?

Test Durable Objects isolation and alarm scheduling using @cloudflare/vitest-pool-workers for unit and integration tests. You can run alarms with runDurableObjectAlarm and verify storage using runInDurableObject to confirm instance isolation.

What is the best way to route requests to a specific Durable Object instance?

The best way to route requests to a specific Durable Object instance is using deterministic routing with getByName or idFromName. This ensures the same input consistently maps to the same instance for tenant-scoped state or game sessions.

Why should I use SQLite-backed durable storage instead of Key-Value for per-entity state?

SQLite-backed durable storage is preferred for per-entity state because it supports schema evolution through migrations using new_sqlite_classes. This provides durable, strongly consistent data management ideal for booking systems and chat message persistence.