CH 27 / 50Chapter 5: Developer Platform

What Are Durable Objects? Workers with State

On this page11 items

The first half of Chapter 5 looked at Workers, Pages and Email Routing — ways to “run things without owning a server.” From here on, we move to mechanisms that make up for the weaknesses of Workers, their foundation.

The Workers page said that “a Worker cannot hold state.” Each request runs independently, and values you put in variables don’t survive until the next access. This property is the price paid for high scalability. In reality, though, some features can’t be built without state: chat rooms, collaborative editing, online games, competition for limited stock. In other words, processing where “multiple people touch the same thing at the same time.”

Durable Objects (“durable” meaning persistent) are stateful Workers built to solve this problem head-on.

What you’ll learn on this page#

  • Why Workers can’t hold state, and when that becomes a problem
  • What it means that a Durable Object is “an instance uniquely determined by its name”
  • Why running operations in order prevents conflicts
  • Built-in storage (SQLite-based) and WebSocket handling
  • Pricing and main limits, and a first look at choosing between KV and D1

Why Workers alone aren’t enough#

As an example, consider online meeting room reservations. Suppose two people press “Reserve” at the same moment for a slot with one seat left.

With regular Workers, these two requests run at different locations around the world, simultaneously, with no knowledge of each other. Both read “one seat left,” and both respond “Reservation complete.” This is a race condition.

The same thing happens with a chat room’s participant list, a game board, or a document being edited collaboratively. You need someone in charge who manages “who is in what state right now” in one place and processes changes in order.

In typical web applications, the database plays this role. But a database lives in a specific location, far from Workers running around the world, and it gets congested when access concentrates. Cloudflare’s answer was to “put the person in charge right at the edge.”

What is a Durable Object? One entity determined by name#

A Durable Object is a small instance with a globally unique name. Everything starts from here.

For example, if you give each meeting room a name like room-123 or room-456, the Durable Object called room-123 exists as exactly one instance in the whole world. Whether access comes from Japan or Germany, specifying room-123 always leads to the same entity.

How processing converges on a Durable Object

This property guarantees two things.

First, it can hold state. Values the instance keeps in memory are still there on the next request. It also has built-in storage dedicated to that object, where you can keep data that survives even a power loss.

Second, operations run in order. A single Durable Object never runs multiple operations at the same time. In the reservation example, the two requests are always processed one after the other, and the second person gets “Fully booked.” Without writing locks or mutual exclusion yourself, conflicts can’t happen by design.

Where Workers “run anywhere but remember nothing,” a Durable Object “exists in only one place but remembers everything.” The basic design combines the two: handle regular processing with Workers, and route only the parts that need coordination to a Durable Object.

Built-in storage#

Each Durable Object has its own dedicated storage. Today the standard approach is built on SQLite (a lightweight database), and you can read and write it with SQL.

What’s special about this storage is that it lives in the same place as the object. Data access is local reading and writing that doesn’t cross the network. It supports transactions and guarantees strong consistency (read right after writing and you always get that value).

While KV, covered in Chapter 6, is designed to “distribute worldwide for fast reads at the cost of slightly delayed propagation,” Durable Object storage is designed to “gather in one place so you always read the correct value.” This difference is what decides which to use.

A good match for WebSockets#

Durable Objects also pair well with WebSockets, which handle real-time communication (a mechanism where the browser and server keep a connection open and exchange messages in both directions).

A single Durable Object can bundle and manage the WebSocket connections of everyone in a chat room. When someone speaks, it simply broadcasts to everyone from right there.

There’s also a mechanism called WebSocket Hibernation, which keeps connections open while evicting the object from memory during periods of no activity. You can maintain many connections while keeping charges down when nobody is talking.

What can you use them for?#

  • Chat and notifications: create a Durable Object per room to manage participants and history
  • Collaborative editing: create an object per document to settle the order of edits
  • Online games: give each match room its own board
  • Inventory, seats and reservations: structurally prevent double booking from simultaneous access
  • Rate limiting and counters: count accurately per user or per API key
  • AI agents: keep conversation context and in-progress tasks (Agents in Chapter 7 is also built on this)

What they have in common is “processing that needs state and ordering per specific unit (room, document, user).”

Pricing and main limits#

They used to be paid-plan only, but SQLite-based Durable Objects are now available on the Free plan as well (as of August 2026).

FreeWorkers Paid
RequestsUp to 100,000 per day1 million per month included, then $0.15 per million
DurationUp to 13,000 GB-s per day400,000 GB-s per month included, then $12.50 per million GB-s
Stored dataUp to 5 GB total per account5 GB included, then $0.20 per GB-month
Rows readUp to 5 million per day25 billion per month included
Rows writtenUp to 100,000 per day50 million per month included

The main limits are:

  • Storage per object: 10 GB
  • Requests: roughly 1,000 per second per object as a guideline (soft limit)
  • CPU time: 30 seconds by default, up to 5 minutes (same as Workers)
  • Number of classes: Free 100 / Paid 500

“Duration (GB-s)” in the pricing table is billed for the time an object exists in memory. Unlike Workers, you pay not only per request but also for the time it’s awake. That’s why the hibernation described above matters.

Points beginners should watch out for#

  • Don’t concentrate too much on a single object: because a Durable Object runs operations in order, it becomes a bottleneck. Avoid designs where all users share one object; split finely, such as per room or per user
  • Placement is decided automatically: an object is created near the region where it was first accessed and stays there. If used from around the world, distant users will see relatively higher latency. If needed, you can specify a location hint at creation time
  • Data is billed until you delete it: leaving objects for finished rooms lying around keeps costing you for stored data. Delete them explicitly when no longer needed
  • First consider whether KV or D1 is enough: figure out whether you truly need state and ordering. For read-heavy settings, KV fits better; for ordinary database use, D1. The choice is revisited in Chapter 6
  • The Free plan supports SQLite-based only: the key-value Durable Objects in older articles are for paid plans. If you’re building something new, choose SQLite-based

Related services#

  • Workers: the side that calls Durable Objects. Handles regular processing (Chapter 5)
  • D1: a database shared across your whole app. A different use case (Chapter 6)
  • Workers KV: the choice when reads dominate and speed matters more than consistency (Chapter 6)
  • Queues / Workflows: mechanisms for asynchronous jobs you want processed in order (next page)
  • Agents: an AI agent framework built on Durable Objects (Chapter 7)

Summary#

  • Workers can’t hold state, so you can’t build processing where multiple users touch the same thing at once
  • A Durable Object is a one-of-a-kind instance in the world, determined by a globally unique name
  • Specify the same name and you always reach the same entity, from anywhere
  • Operations run in order, so race conditions can’t occur by design
  • It has built-in SQLite-based storage with strongly consistent reads and writes
  • It’s well suited to bundling WebSockets, and hibernation keeps idle costs down
  • Now available on the Free plan too, provided you design so as not to concentrate on one object

The next page covers Queues and Workflows, mechanisms that also deal with ordering and reliability: ways to safely defer “work that doesn’t need an immediate response.”

Read next#