Skip to main content
Durable Objects are single-instance, stateful Workers that Cloudflare routes all traffic for a given ID to the same physical server — making them ideal for chat rooms, presence systems, collaborative editing, game sessions, and any use case where you need globally consistent state without an external database. Blaze gives you access to your Durable Object namespaces via req.env using the same type-safe pattern as every other binding, so forwarding a request to a specific DO instance is just a few lines of code.

Configure the binding

1

Declare the Durable Object in wrangler.toml

wrangler.toml
2

Define the Env type

src/types/env.ts
3

Pass Env to createApp

src/index.ts
The Durable Object class (ChatRoom in the example above) must be defined and exported separately in your Worker entry point. The class must extend DurableObject and implement a fetch(request) method. Blaze handles the HTTP routing layer; your DO class handles the stateful logic.
src/durable-objects/chat-room.ts
Then re-export it from your entry point:
src/index.ts

Getting a DO instance

Every Durable Object instance is identified by a DurableObjectId. Derive an ID in one of two ways:

Forwarding requests to a DO

The most common pattern is to forward the entire incoming request — including a WebSocket upgrade — directly to the Durable Object. The DO handles the upgrade and owns the persistent connection state.
You can forward any request type — REST calls, streaming, RPC — not just WebSocket upgrades:

Named instances

idFromName() is the building block for stable, long-lived DO instances tied to application entities. Use a consistent naming scheme so every part of your application resolves to the same instance for a given entity.
Named Durable Objects created with idFromName() are permanent — they are not garbage-collected until you explicitly delete them via the Cloudflare API or Wrangler. Design your naming scheme carefully; a new DO instance is provisioned the first time an ID is accessed, and storage costs accrue from that point forward.