Durable Object foundations

Route deterministically to an instance

Use getByName for stable entity routing and keep authorization outside the fact that an object name can be guessed.

8 minute lesson

~~~

A Durable Object namespace maps a name or ID to one instance. getByName(roomId) is the direct choice when the same room ID must always reach the same object.

The name is routing information, not authentication. Verify the caller before creating the stub or inside the RPC method. Use new unique IDs only when you have somewhere durable to store the mapping.

Route two test room names, call each twice, and prove state is shared within a room but isolated between rooms.

Derive the object ID from the entity that owns coordination:

const id = env.ROOMS.idFromName(roomId)
const room = env.ROOMS.get(id)
return room.fetch(request)

The same roomId reaches the same logical object. Do not include a random request ID in this name or every request creates a different coordination boundary. Test two users in one room and one user in another room to prove isolation.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →