Agent Skill

Cloudflare Durable Objects
Create stateful coordination systems on Cloudflare with Durable Objects for chat rooms, multiplayer games, booking systems, and real-time collaboration
What is Cloudflare Durable Objects?
This skill instructs agents on building stateful, coordinated applications using Cloudflare Durable Objects, which provide strongly consistent, single-threaded compute instances with persistent storage. The skill covers defining Durable Object classes with RPC methods for client invocation, implementing SQLite storage for persistent state management, using alarms for scheduled operations, handling WebSocket connections for real-time bidirectional communication, integrating Durable Objects with Workers for routing and coordination, configuring wrangler for development and deployment, and testing with Vitest. The agent learns architectural patterns for common use cases like chat rooms requiring message broadcasting, multiplayer games needing conflict-free state updates, booking systems demanding strong consistency to prevent double-booking, and collaborative editing requiring coordination between concurrent users. The skill establishes boundaries around when to use Durable Objects versus simpler storage like KV—choose Durable Objects when you need coordination, transactions, or real-time features, not just key-value retrieval. Trade-offs include understanding the single-threaded execution model's implications for performance, managing the lifecycle of Durable Object instances, and balancing between storage in memory versus SQLite for different durability guarantees.
Key capabilities
Strongly consistent state management
Provides single-threaded execution guarantees ensuring state consistency without race conditions, critical for booking systems, inventory management, and coordination scenarios
SQLite integration for persistent storage
Embeds SQLite databases within Durable Object instances, enabling relational queries, transactions, and durable storage with familiar SQL syntax
RPC method invocation pattern
Exposes class methods as callable RPC endpoints from Workers, enabling clean separation between routing logic and stateful operations with typed interfaces
WebSocket connection management
Handles multiple concurrent WebSocket connections within a single Durable Object, broadcasting messages to connected clients and managing connection lifecycles for real-time applications
Use cases
Multi-user chat room implementation
Build chat rooms where each room is a Durable Object managing WebSocket connections, broadcasting messages to participants, persisting message history to SQLite, and handling user presence
Collaborative document editing
Implement real-time collaborative editing where a Durable Object coordinates concurrent edits, resolves conflicts, broadcasts changes via WebSocket, and maintains document state
Inventory management with strong consistency
Create booking or inventory systems where Durable Objects prevent double-booking through single-threaded execution, maintain accurate counts, and handle reservation workflows transactionally
Multiplayer game state coordination
Manage game sessions where each game instance is a Durable Object maintaining authoritative game state, processing player actions in order, and broadcasting updates to connected players
Compatibility
- @cloudflare/workers-types
