Skip to content

Conversation

@kentonv
Copy link
Member

@kentonv kentonv commented Sep 19, 2025

Summary

Documentation for the still-experimental Dynamic Worker Loading feature, as well as ctx.props (which has been around a while, undocumented) and ctx.exports (which will hopefully be unflagged "experimental" soon).

Documentation checklist

  • Is there a changelog entry (guidelines)? If you don't add one for something awesome and new (however small) — how will our customers find out? Changelogs are automatically posted to RSS feeds, the Discord, and X.
  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.

@github-actions github-actions bot added product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workers Related to Workers product September 2025 size/m labels Sep 19, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/changelog/ @cloudflare/pm-changelogs, @cloudflare/pcx-technical-writing
/src/content/compatibility-flags/ @irvinebroque, @mikenomitch, @GregBrimble, @cloudflare/pcx-technical-writing
/src/content/docs/durable-objects/ @elithrar, @vy-ton, @joshthoward, @oxyjun, @harshil1712, @mikenomitch, @cloudflare/pcx-technical-writing, @cloudflare/workers-runtime-1
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @kodster28, @cloudflare/wrangler, @cloudflare/workers-runtime-1

@kentonv
Copy link
Member Author

kentonv commented Sep 19, 2025

I feel like this is tucking some very important stuff into the "context" page which previously didn't matter that much. We probably want more of an overview somewhere but I don't really have a sense of where to put that or how to structure it.

@kentonv kentonv requested a review from a team as a code owner September 25, 2025 20:00
@kentonv kentonv force-pushed the kenton/dynamic-worker-loading branch from 39aac82 to dbc1630 Compare September 25, 2025 20:01
date: 2025-09-26
---

The [`ctx.exports` API](/workers/runtime-apis/context/#exports) contains automatically-configured bindings corresponding to your Worker's top-level exports. For each top-level export extending `WorkerEntrypoint`, `ctx.exports` will contain a [Service Binding](/workers/runtime-apis/bindings/service-bindings) by the same name, and for each export extending `DurableObject` (and for which storage has been configured via a [migration](/durable-objects/reference/durable-objects-migrations/)), `ctx.exports` will contain a [Durable Object namespace binding](/durable-objects/api/namespace/). This means you no longer have to configure these bindings explicitly in `wrangler.jsonc`/`wrangler.toml`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy over this code snippet?

https://github.com/cloudflare/cloudflare-docs/pull/25303/files#diff-7157aec1a3a350afe6de7fce2cef85501751923d7af1509ee0fee060811039e4R80-R95

so that the reader can read the code snippet and "get it" faster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do before/after

Before:

example code

After:

<less config / zero config>
example code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied the example, not really feeling how to do before/after.


Loads a Worker with the given ID.

As a convenience, the loader implements basic caching of isolates: If this loader has already been used to load a Worker with the same ID in the past, and that Worker's isolate is still resident in memory, then the existing Worker will be returned, and the callback will not be called. When an isolate has not been used in a while, the system will discard it automatically, and then the next attempt to get the same ID will have to load it again. If you frequently run the same code, you should use the same ID in order to get automatic caching. On the other hand, if the code you load is different every time, you can provide a random ID. Note that if your code has many versions, each version will need a unique ID, as there is no way to explicitly evict a previous version.
Copy link
Contributor

@irvinebroque irvinebroque Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As a convenience, the loader implements basic caching of isolates: If this loader has already been used to load a Worker with the same ID in the past, and that Worker's isolate is still resident in memory, then the existing Worker will be returned, and the callback will not be called. When an isolate has not been used in a while, the system will discard it automatically, and then the next attempt to get the same ID will have to load it again. If you frequently run the same code, you should use the same ID in order to get automatic caching. On the other hand, if the code you load is different every time, you can provide a random ID. Note that if your code has many versions, each version will need a unique ID, as there is no way to explicitly evict a previous version.
As a convenience, the loader implements basic caching of isolates: If this loader has already been used to load a Worker with the same ID in the past, and that Worker's isolate is still resident in memory, then the existing Worker will be returned, and the callback will not be called. When an isolate has not been used in a while, the system will discard it automatically, and then the next attempt to get the same ID will have to load it again.
This means that anytime you update any value returned by the callback (the isolate's code and its configuration), you must use a different ID if you need to guarantee that the updated values will be used.
Best practices:
- If you frequently run the same code with the same configuration provided in the callback, you should use the same ID in order to get automatic caching.
- If the code or configuration you load is different every time, you should provide a random ID.
Note that if your code has many versions, each version will need a unique ID, as there is no way to explicitly evict a previous version.

Thinking about ways to be explicit to people that this means not just that if the code changes you need new ID, but that if the config provided via the callback changes, you also need new ID...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riffing on how to be super clear about this...can take or leave language

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time as you were suggesting this I was tweaking my own text a bit, but now I gotta run, so I'll come back and see if I can merge yours and mine later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I rewrote this section again, I think it's clearer now, hopefully.

@kentonv kentonv merged commit df078c6 into production Sep 26, 2025
8 checks passed
@kentonv kentonv deleted the kenton/dynamic-worker-loading branch September 26, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workers Related to Workers product September 2025 size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.