Durable Objects provide low-latency coordination and consistent storage for the Workers platform. Use the API to manage Durable Object namespaces.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/cloudflare-typescript/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Access the Durable Objects API:Namespaces
Durable Object namespaces are containers for Durable Object instances.List namespaces
Retrieve all Durable Object namespaces in your account.Your Cloudflare account ID
Page number for pagination
Number of namespaces per page (default: 20, max: 100)
The namespace ID
The namespace name
The Worker script that defines the Durable Object class
The exported class name in the Worker script
Creating Durable Objects
Durable Objects are created through Worker bindings. You define the class in your Worker script and bind it using migrations.Example: Define a Durable Object class
In your Worker script:Example: Configure bindings
When deploying your Worker, configure Durable Object bindings:Set to ‘durable_object_namespace’
The binding name (accessible as env.COUNTER in your Worker)
The exported Durable Object class name
The Worker script that exports the class (defaults to current script)
Migrations
When deploying Workers with Durable Objects, you need to specify migrations to create, rename, or delete Durable Object classes.Example: Create a new Durable Object class
Array of class names to create
Array of objects with ‘from’ and ‘to’ properties for renaming classes
Array of class names to delete
Array of class names to create with SQLite storage
Example: Rename a Durable Object class
Using Durable Objects in Workers
Once configured, access Durable Objects from your Worker:Best practices
- Unique IDs: Use
idFromName()for deterministic IDs ornewUniqueId()for random IDs - State management: Use
state.storagefor persistent data with strong consistency - Concurrency: Durable Objects handle one request at a time, ensuring strong consistency
- Migrations: Always specify migrations when adding, renaming, or removing Durable Object classes
- SQLite storage: Use
new_sqlite_classesfor SQL-based storage in Durable Objects