Skip to content

[Workers] Multi Workers development #23122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

edmundhung
Copy link
Member

@edmundhung edmundhung commented Jun 19, 2025

Summary

This adds a Multi Worker development guide under Development & testing to showcase the different approaches to run multiple Workers locally and when to use each approach.

Screenshots (optional)

Documentation checklist

  • 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.
  • Files which have changed name or location have been allocated redirects.

Copy link
Contributor

hyperlint-ai bot commented Jun 19, 2025

Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment.

We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.


PR Change Summary

Added a comprehensive guide on developing with multiple Workers, detailing various approaches and configurations.

  • Introduced a new guide for Multi Workers development.
  • Outlined methods for running multiple Workers in single and multiple processes.
  • Provided a hybrid approach for combining different Worker setups.
  • Included best practices for choosing between single and multiple process approaches.

Added Files

  • src/content/docs/workers/development-testing/multi-workers.mdx

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

Copy link
Contributor

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

Pattern Owners
/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, @cloudflare/wrangler

Copy link
Contributor

github-actions bot commented Jun 19, 2025

@edmundhung edmundhung force-pushed the edmundhung/multi-workers-development branch 3 times, most recently from 67adec5 to 7ca0616 Compare June 20, 2025 18:45
@edmundhung edmundhung marked this pull request as ready for review June 20, 2025 18:51
@edmundhung edmundhung force-pushed the edmundhung/multi-workers-development branch 2 times, most recently from 9c8216b to fde2029 Compare June 23, 2025 14:49
Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

Thank you for adding this—this is great to have on our docs!


- Workers are closely related or part of the same application
- You want the simplest development setup
- You need to access a Durable Object namespace from another Worker using `script_name`
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should have a "limitations" section?


Use this approach when:

- Each Worker uses a different build configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean Vite vs Wrangler?


- Workers are closely related or part of the same application
- You want the simplest development setup
- You need to access a Durable Object namespace from another Worker using `script_name`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- You need to access a Durable Object namespace from another Worker using `script_name`
- You want to use RPC to a Durable Object namespace from another Worker (i.e. using `script_name`)

Comment on lines 112 to 113
- Different teams maintain the Workers
- A Worker only occasionally accesses another, and you prefer the flexibility to run them separately
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't really see why these are necessarily the case? it seems pretty reasonable to me to run all workers in one dev session for the last two points here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the wording to clarify it better. Hope this helps.

- Workers are closely related or part of the same application
- You want the simplest development setup
- You need to access a Durable Object namespace from another Worker using `script_name`

Copy link
Contributor

Choose a reason for hiding this comment

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

also maybe mention if one of your projects is pages, and you also have some workers alongside, you can use wranlger pages with multiple configs

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if we should include Pages here as this is under the Worker docs 🤔

Comment on lines 134 to 137
Use this approach when:

- You have an independent Worker that is shared across multiple applications
- You are integrating with a legacy Worker that you don't want to refactor yet
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think any of these points necessarily mean you have to do this - afaict, the only reason is if you want to use vite for some but not all workers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. It's fine for people to use either wrangler or vite. This is more about having a legacy Worker in a different setup that your main Worker. Updated the wording to reflect that better.


- Workers are closely related or part of the same application
- You want the simplest development setup
- You need to access a Durable Object namespace from another Worker using `script_name`
Copy link
Contributor

Choose a reason for hiding this comment

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

i think queues with separate producer/consumers requires this set up too: https://developers.cloudflare.com/queues/configuration/local-development/#separating-producer--consumer-workers

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call! Added this to the simple command section.

@emily-shen
Copy link
Contributor

should we link to the vitest section on multiple workers too? and also something about type gen

@irvinebroque
Copy link
Contributor

There's something about this explanation (screenshot below) that made it hard for me to understand that this boils down to basically:

"To run multiple Workers from one local dev session, for each Worker, add -c ../path/to/wrangler.jsonc to wrangler dev:

npx wrangler dev -c wrangler.jsonc -c ../api/wrangler.jsonc

The first wrangler.jsonc you pass to wrangler dev is treated as the "primary" Worker — it runs in response to incoming requests, and is available on localhost. Any additional configurations you provide are available as bindings to this "primary" Worker.

<then, after saying this, show the example>

Screenshot 2025-06-23 at 11 58 43 AM

Copy link
Contributor

@irvinebroque irvinebroque left a comment

Choose a reason for hiding this comment

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

Glad we are documenting this - so that we can look at it and see what we can make simpler

✅ so that you have a stamp but see comments

@edmundhung edmundhung force-pushed the edmundhung/multi-workers-development branch 2 times, most recently from 0fc5134 to c48df1d Compare June 25, 2025 15:37
@edmundhung
Copy link
Member Author

should we link to the vitest section on multiple workers too? and also something about type gen

I think this guide is better focus on the different approaches we offered and when to use them, which doesn't matter with vitest / type gen.

There's something about this explanation (screenshot below) that made it hard for me to understand that this boils down to basically: ...

I removed to example wrangler config to focus on the dev commands and vite config required.

@edmundhung edmundhung force-pushed the edmundhung/multi-workers-development branch 2 times, most recently from 43a73c3 to f3acf66 Compare June 26, 2025 12:10
@edmundhung edmundhung force-pushed the edmundhung/multi-workers-development branch from f3acf66 to 7b7b7a5 Compare June 26, 2025 14:00
@github-actions github-actions bot added size/s and removed size/m labels Jun 26, 2025
@edmundhung edmundhung merged commit b129c48 into production Jun 26, 2025
11 checks passed
@edmundhung edmundhung deleted the edmundhung/multi-workers-development branch June 26, 2025 14:38
sdnts pushed a commit to sdnts/cloudflare-docs that referenced this pull request Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product:workers Related to Workers product size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants