Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cloudflare avatar

Durable Objects

  • 29.5k installs
  • 2.5k repo stars
  • Updated July 24, 2026
  • cloudflare/skills

durable-objects is a Cloudflare Workers skill that teaches sharding, parent-child hierarchies, and coordination-atom patterns so developers avoid global Durable Object bottlenecks in stateful edge apps.

About

durable-objects is a Cloudflare Workers skill that teaches sharding, parent-child hierarchies, and coordination-atom patterns so developers avoid global Durable Object bottlenecks in stateful edge apps. Covers SQLite storage, migrations, concurrency gates, and WebSocket integration for real-time collaboration, multiplayer games, and per-user state.

  • Model around coordination atoms with one DO per logical unit such as chat room or game session
  • Establishes correct parent-child relationships so parents track references while children manage their own state
  • Uses location hints for latency-sensitive applications

Durable Objects by the numbers

  • 29,479 all-time installs (skills.sh)
  • +4,397 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #36 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

durable-objects capabilities & compatibility

Works with
cloudflare
Use cases
api development
From the docs

What durable-objects says it does

Create one DO per logical unit needing coordination: chat room, game session, document, user, tenant.
readmeExcerpt
npx skills add https://github.com/cloudflare/skills --skill durable-objects

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs29.5k
repo stars2.5k
Security audit3 / 3 scanners passed
Last updatedJuly 24, 2026
Repositorycloudflare/skills

How do you shard Cloudflare Durable Objects correctly?

Learn sharding, parent-child hierarchies, and coordination-atom patterns to avoid global Durable Object bottlenecks in stateful edge apps.

Who is it for?

Backend developers building stateful Cloudflare Workers apps with chat, games, or per-tenant coordination needs.

Skip if: Developers on AWS Lambda, Vercel, or stateless Workers routes that never need strongly consistent per-entity state.

When should I use this skill?

A developer designs or reviews Cloudflare Durable Objects for chat, games, documents, or multi-tenant coordination.

What you get

TypeScript DO design patterns, sharding rules, and parent-child hierarchy examples for Workers projects.

  • DO sharding patterns
  • parent-child hierarchy examples
  • anti-pattern checklist

By the numbers

  • Defines 5 coordination-atom examples: chat room, game session, document, user, tenant

Files

SKILL.mdMarkdownGitHub ↗

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

// wrangler.jsonc
{
  "durable_objects": {
    "bindings": [{ "name": "MY_DO", "class_name": "MyDurableObject" }]
  },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyDurableObject"] }]
}

Basic Durable Object Pattern

import { DurableObject } from "cloudflare:workers";

export interface Env {
  MY_DO: DurableObjectNamespace<MyDurableObject>;
}

export class MyDurableObject extends DurableObject<Env> {
  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    ctx.blockConcurrencyWhile(async () => {
      this.ctx.storage.sql.exec(`
        CREATE TABLE IF NOT EXISTS items (
          id INTEGER PRIMARY KEY AUTOINCREMENT,
          data TEXT NOT NULL
        )
      `);
    });
  }

  async addItem(data: string): Promise<number> {
    const result = this.ctx.storage.sql.exec<{ id: number }>(
      "INSERT INTO items (data) VALUES (?) RETURNING id",
      data
    );
    return result.one().id;
  }
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const stub = env.MY_DO.getByName("my-instance");
    const id = await stub.addItem("hello");
    return Response.json({ id });
  },
};

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

// Deterministic - preferred for most cases
const stub = env.MY_DO.getByName("room-123");

// From existing ID string
const id = env.MY_DO.idFromString(storedIdString);
const stub = env.MY_DO.get(id);

// New unique ID - store mapping externally
const id = env.MY_DO.newUniqueId();
const stub = env.MY_DO.get(id);

Storage Operations

// SQL (synchronous, recommended)
this.ctx.storage.sql.exec("INSERT INTO t (c) VALUES (?)", value);
const rows = this.ctx.storage.sql.exec<Row>("SELECT * FROM t").toArray();

// KV (async)
await this.ctx.storage.put("key", value);
const val = await this.ctx.storage.get<Type>("key");

Alarms

// Schedule (replaces existing)
await this.ctx.storage.setAlarm(Date.now() + 60_000);

// Handler
async alarm(): Promise<void> {
  // Process scheduled work
  // Optionally reschedule: await this.ctx.storage.setAlarm(...)
}

// Cancel
await this.ctx.storage.deleteAlarm();

Testing Quick Start

import { env } from "cloudflare:test";
import { describe, it, expect } from "vitest";

describe("MyDO", () => {
  it("should work", async () => {
    const stub = env.MY_DO.getByName("test");
    const result = await stub.addItem("test");
    expect(result).toBe(1);
  });
});

Related skills

Forks & variants (1)

Durable Objects has 1 known copy in the catalog totaling 2 installs. They canonicalize to this original listing.

How it compares

Pick durable-objects when building stateful coordination on Cloudflare Workers rather than generic Workers routing skills.

FAQ

How many Durable Objects should one chat room use?

durable-objects recommends one Durable Object per logical coordination unit such as a chat room, game session, document, user, or tenant. A single global DO becomes a bottleneck; getByName(roomId) keeps each room isolated.

When should Durable Objects use parent-child hierarchies?

durable-objects advises parent-child splits when data is hierarchical: a parent GameServer DO tracks match references while child GameMatch DOs own individual match state, avoiding one oversized object.

Is Durable Objects safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.