Durable Objects
What is it?
Durable Objects provide strongly consistent storage and coordination for applications built on Workers. While KV is eventually consistent and globally distributed, Durable Objects guarantee that there is exactly one instance of each object running at any time, anywhere in the world. This makes them perfect for applications that need real-time coordination — like chat rooms, collaborative editors, multiplayer games, and rate limiters.
What problem does it solve?
Some applications need guarantees that KV and simple key-value stores can't provide:
- Consistency: If two users update the same piece of data at the same time, the result must be deterministic. Eventually consistent stores can lose writes.
- Coordination: Chat applications, multiplayer games, and collaborative tools need a single source of truth that multiple clients can connect to simultaneously.
- WebSockets: Long-lived connections (like WebSockets) need a persistent endpoint. Standard serverless functions are short-lived and stateless.
- Counters and rate limiters: Accurate counting requires strong consistency — eventual consistency means counts can drift.
How does it work?
- Each Durable Object is a JavaScript class with its own unique ID.
- Cloudflare guarantees global uniqueness: only one instance of a Durable Object with a given ID is running at any time, anywhere in the world.
- The object is automatically placed in the Cloudflare data center closest to where it's first accessed, minimizing latency.
- The object has a transactional SQLite database for persistent storage — reads and writes are strongly consistent.
- Multiple clients (Workers, WebSocket connections) can send requests to the same Durable Object, and the object processes them single-threaded, ensuring consistency.
Use cases:
- Chat rooms: Each chat room is a Durable Object. Users connect via WebSocket. The object manages messages, user presence, and history.
- Collaborative editing: A document is a Durable Object. Multiple editors connect simultaneously, and the object coordinates their changes.
- Rate limiting: A rate limiter per API key is a Durable Object, ensuring accurate counting across all edge locations.
- IoT: Each device is a Durable Object, maintaining its own state.
Why it matters strategically
Durable Objects solve the hardest problem in distributed systems: coordination. They're a genuinely novel product that has no direct equivalent in AWS, Google Cloud, or Azure. This uniqueness makes them a key differentiator for Cloudflare's developer platform and attracts developers building real-time, collaborative, and AI agent applications.