KS
Killer-Skills

durable-objects — how to use durable-objects how to use durable-objects, what is durable-objects, durable-objects alternative, durable-objects vs cloud storage, durable-objects install guide, durable-objects setup for AI agents, cloudflare durable objects tutorial, durable objects rpc methods, durable objects sqlite storage

Verified
v1.0.0
GitHub

About this Skill

Essential for Cloudflare Workers Agents building stateful, coordinated applications on the edge. Durable-objects is a Cloudflare feature for building stateful, coordinated applications on the edge, using APIs and configuration for tasks like chat rooms and multiplayer games.

Features

Builds stateful coordination applications like chat rooms and multiplayer games
Supports Workers integration for edge computing
Configures wrangler for efficient deployment
Tests applications with Vitest for reliability
Implements RPC methods for remote communication
Utilizes SQLite storage for data management

# Core Topics

cloudflare cloudflare
[535]
[66]
Updated: 3/6/2026

Quality Score

Top 5%
89
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add cloudflare/skills/durable-objects

Agent Capability Analysis

The durable-objects MCP Server by cloudflare is an open-source Categories.official integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use durable-objects, what is durable-objects, durable-objects alternative.

Ideal Agent Persona

Essential for Cloudflare Workers Agents building stateful, coordinated applications on the edge.

Core Value

Enables agents to create and manage stateful coordination systems like chat rooms, multiplayer games, and booking systems using Durable Objects' RPC methods, SQLite storage, alarms, and WebSocket integrations. Provides direct access to current Cloudflare Workers configurations, Wrangler setup, and Vitest testing protocols.

Capabilities Granted for durable-objects MCP Server

Implementing stateful RPC methods for edge coordination
Configuring SQLite storage within Durable Objects
Setting up WebSocket connections for real-time applications
Creating and managing alarms for timed operations
Reviewing Durable Object code for Cloudflare best practices

! Prerequisites & Limits

  • Requires retrieval from Cloudflare documentation for current API specs
  • Dependent on Cloudflare Workers ecosystem integration
  • Limited to Cloudflare's Durable Objects implementation
Project
SKILL.md
5.3 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8
SKILL.md
Readonly

Durable Objects

Build stateful, coordinated applications on Cloudflare's edge using Durable Objects.

Retrieval Sources

Your knowledge of Durable Objects APIs and configuration may be outdated. Prefer retrieval over pre-training for any Durable Objects task.

ResourceURL
Docshttps://developers.cloudflare.com/durable-objects/
API Referencehttps://developers.cloudflare.com/durable-objects/api/
Best Practiceshttps://developers.cloudflare.com/durable-objects/best-practices/
Exampleshttps://developers.cloudflare.com/durable-objects/examples/

Fetch the relevant doc page when implementing features.

When to Use

  • Creating new Durable Object classes for stateful coordination
  • Implementing RPC methods, alarms, or WebSocket handlers
  • Reviewing existing DO code for best practices
  • Configuring wrangler.jsonc/toml for DO bindings and migrations
  • Writing tests with @cloudflare/vitest-pool-workers
  • Designing sharding strategies and parent-child relationships

Reference Documentation

  • ./references/rules.md - Core rules, storage, concurrency, RPC, alarms
  • ./references/testing.md - Vitest setup, unit/integration tests, alarm testing
  • ./references/workers.md - Workers handlers, types, wrangler config, observability

Search: blockConcurrencyWhile, idFromName, getByName, setAlarm, sql.exec

Core Principles

Use Durable Objects For

NeedExample
CoordinationChat rooms, multiplayer games, collaborative docs
Strong consistencyInventory, booking systems, turn-based games
Per-entity storageMulti-tenant SaaS, per-user data
Persistent connectionsWebSockets, real-time notifications
Scheduled work per entitySubscription renewals, game timeouts

Do NOT Use For

  • Stateless request handling (use plain Workers)
  • Maximum global distribution needs
  • High fan-out independent requests

Quick Reference

Wrangler Configuration

jsonc
1// wrangler.jsonc 2{ 3 "durable_objects": { 4 "bindings": [{ "name": "MY_DO", "class_name": "MyDurableObject" }] 5 }, 6 "migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyDurableObject"] }] 7}

Basic Durable Object Pattern

typescript
1import { DurableObject } from "cloudflare:workers"; 2 3export interface Env { 4 MY_DO: DurableObjectNamespace<MyDurableObject>; 5} 6 7export class MyDurableObject extends DurableObject<Env> { 8 constructor(ctx: DurableObjectState, env: Env) { 9 super(ctx, env); 10 ctx.blockConcurrencyWhile(async () => { 11 this.ctx.storage.sql.exec(` 12 CREATE TABLE IF NOT EXISTS items ( 13 id INTEGER PRIMARY KEY AUTOINCREMENT, 14 data TEXT NOT NULL 15 ) 16 `); 17 }); 18 } 19 20 async addItem(data: string): Promise<number> { 21 const result = this.ctx.storage.sql.exec<{ id: number }>( 22 "INSERT INTO items (data) VALUES (?) RETURNING id", 23 data 24 ); 25 return result.one().id; 26 } 27} 28 29export default { 30 async fetch(request: Request, env: Env): Promise<Response> { 31 const stub = env.MY_DO.getByName("my-instance"); 32 const id = await stub.addItem("hello"); 33 return Response.json({ id }); 34 }, 35};

Critical Rules

  1. Model around coordination atoms - One DO per chat room/game/user, not one global DO
  2. Use getByName() for deterministic routing - Same input = same DO instance
  3. Use SQLite storage - Configure new_sqlite_classes in migrations
  4. Initialize in constructor - Use blockConcurrencyWhile() for schema setup only
  5. Use RPC methods - Not fetch() handler (compatibility date >= 2024-04-03)
  6. Persist first, cache second - Always write to storage before updating in-memory state
  7. One alarm per DO - setAlarm() replaces any existing alarm

Anti-Patterns (NEVER)

  • Single global DO handling all requests (bottleneck)
  • Using blockConcurrencyWhile() on every request (kills throughput)
  • Storing critical state only in memory (lost on eviction/crash)
  • Using await between related storage writes (breaks atomicity)
  • Holding blockConcurrencyWhile() across fetch() or external I/O

Stub Creation

typescript
1// Deterministic - preferred for most cases 2const stub = env.MY_DO.getByName("room-123"); 3 4// From existing ID string 5const id = env.MY_DO.idFromString(storedIdString); 6const stub = env.MY_DO.get(id); 7 8// New unique ID - store mapping externally 9const id = env.MY_DO.newUniqueId(); 10const stub = env.MY_DO.get(id);

Storage Operations

typescript
1// SQL (synchronous, recommended) 2this.ctx.storage.sql.exec("INSERT INTO t (c) VALUES (?)", value); 3const rows = this.ctx.storage.sql.exec<Row>("SELECT * FROM t").toArray(); 4 5// KV (async) 6await this.ctx.storage.put("key", value); 7const val = await this.ctx.storage.get<Type>("key");

Alarms

typescript
1// Schedule (replaces existing) 2await this.ctx.storage.setAlarm(Date.now() + 60_000); 3 4// Handler 5async alarm(): Promise<void> { 6 // Process scheduled work 7 // Optionally reschedule: await this.ctx.storage.setAlarm(...) 8} 9 10// Cancel 11await this.ctx.storage.deleteAlarm();

Testing Quick Start

typescript
1import { env } from "cloudflare:test"; 2import { describe, it, expect } from "vitest"; 3 4describe("MyDO", () => { 5 it("should work", async () => { 6 const stub = env.MY_DO.getByName("test"); 7 const result = await stub.addItem("test"); 8 expect(result).toBe(1); 9 }); 10});

Related Skills

Looking for an alternative to durable-objects or building a Categories.official AI Agent? Explore these related open-source MCP Servers.

View All

flags

Logo of facebook
facebook

flags is a feature flag management system that enables developers to check flag states, compare channels, and debug feature behavior differences across release channels.

243.6k
0
Design

extract-errors

Logo of facebook
facebook

extract-errors is a skill that assists in extracting and managing error codes in React applications using yarn extract-errors command.

243.6k
0
Design

fix

Logo of facebook
facebook

fix is a technical skill that resolves lint errors, formatting issues, and ensures code quality in declarative, frontend, and UI projects

243.6k
0
Design

flow

Logo of facebook
facebook

Flow is a type checking system for JavaScript, used to validate React code and ensure consistency across applications

243.6k
0
Design