Back to Docs
Recipe

Durable Objects

Single-tenant stateful compute that stays alive across requests. Build real-time collaboration, session coordination, and transactional workflows without external databases.

What They Are

A Durable Object is a JavaScript class instance pinned to a unique ID. The runtime guarantees exactly one instance exists globally per ID, with its in-memory state surviving between requests. Think of it as a single-threaded actor model — no locks, no race conditions, just sequential message processing.

When to Use

  • Real-time multiplayer state (cursor positions, document snapshots)
  • Rate limiting and token buckets scoped per user
  • Transactional workflows requiring ordered steps
  • WebSocket hubs broadcasting to connected clients

Lifecycle

Objects are created on first access and evicted after idle timeout. During eviction, persistent storage flushes to disk automatically. The runtime handles global uniqueness — two requests for the same ID always land on the same instance, even across data centers.

Key Insight

Durable Objects eliminate the need for external state stores in latency-sensitive paths. State lives in memory on the edge, not across a network round-trip to Redis or Postgres.