durable-objects

Implement stateful Cloudflare Durable Objects with RPC methods, alarms, and SQLite storage.

17|1|Updated Feb 2, 2024
One-click install
npx skills add https://github.com/FormalSnake/dotfiles --skill durable-objects-formalsnake
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/FormalSnake/dotfiles/tree/main/users/kyandesutter/claude/skills/durable-objects
Command: npx skills add https://github.com/FormalSnake/dotfiles --skill durable-objects-formalsnake

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you build and review stateful, strongly coordinated application logic on Cloudflare’s edge without turning concurrency, storage, and routing into guesswork.

Core Features & Use Cases

  • Durable Object design guidance: Choose when Durable Objects are appropriate and structure coordination around the right “coordination atoms” (e.g., per room/game/user).
  • Correct routing & identity patterns: Use deterministic instance selection (getByName, idFromName) and apply appropriate stub creation strategies.
  • Production-grade implementation rules: Persist primary data with Durable Objects SQLite storage, initialize with blockConcurrencyWhile only during setup, prefer RPC methods over fetch, and structure alarms and WebSocket handling safely.
  • Testing and review support: Validate behavior with Vitest using @cloudflare/vitest-pool-workers and apply best-practice review heuristics for concurrency and storage safety.

Quick Start

Ask it to help you implement a Durable Object RPC method that stores per-entity state in SQLite, schedules a per-instance alarm, and provides a Vitest test plan for the method and alarm behavior.

Frequently Asked Questions about durable-objects

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

FAQPage Schema
How do I build stateful coordination with Cloudflare Durable Objects?

Stateful coordination with Cloudflare Durable Objects is built by defining per-entity instances, routing requests deterministically using getByName, and persisting data via SQLite storage with RPC methods.

When should I use Durable Objects SQLite storage instead of external databases?

Durable Objects SQLite storage is ideal when you need strongly consistent, coordinated state for specific entities like chat rooms or game sessions, persisting primary data locally with SQL exec semantics.

How do I test Cloudflare Durable Objects alarms and RPC methods?

Test Durable Objects alarms and RPC methods using Vitest with the @cloudflare/vitest-pool-workers package, which allows you to validate per-instance alarm behavior and storage-first persistence safely.

Does Cloudflare Workers support WebSocket handlers and alarms in Durable Objects?

Cloudflare Workers supports WebSocket handlers and alarms in Durable Objects by structuring safe WebSocket connections and scheduling per-instance alarms alongside RPC-style methods for coordinated application entities.

What is the correct way to use blockConcurrencyWhile during Durable Object initialization?

blockConcurrencyWhile should be used during Durable Object initialization only for setup tasks, ensuring safe blockConcurrencyWhile usage without blocking normal request handling or storage operations afterward.

How do I route requests to a specific Durable Object instance deterministically?

Route requests to a specific Durable Object instance deterministically by using idFromName to generate a consistent ID and getByName to create the appropriate stub for your coordination atom.