Skip to content
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

🚀 Feature Request: Multiple workers support + shared resources #4452

Closed
iustinpericica opened this issue Nov 15, 2023 · 5 comments
Closed
Labels
awaiting reporter response Needs clarification or followup from OP enhancement New feature or request

Comments

@iustinpericica
Copy link

iustinpericica commented Nov 15, 2023

Describe the solution

I'm trying to set up locally few workers that access shared resources like D1, KV in prod env.
Let's take an example to make things easier.
WorkerA with access to D1_A, KV_A, KV_B
WorkerB with access to D1_A, KV_B.

I'm struggling to set up proper development experience which is to start multiple workers with wrangler, make the bindings to each of them work and most important, share the database resources between each other ( WorkerA and WorkerB point to same instance of KV_B and D1_A and not set one resource instance/ worker ).

Without the possibility of sharing resources and make the bindings work, it is impossible to properly develop locally an application in such scenario?

@iustinpericica iustinpericica added the enhancement New feature or request label Nov 15, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Nov 15, 2023
@mrbbot
Copy link
Contributor

mrbbot commented Nov 21, 2023

Hey @iustinpericica! 👋 For developing multiple workers locally with access to shared bindings, I would encourage you to use Miniflare's API directly. See the example on this page https://miniflare.dev/core/multiple-workers and the API docs here https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/README.md.

You should be able to get this working with Wrangler too though. Start a wrangler dev session in each of your worker directories and they should automatically connect, with service bindings between them sending requests to the correct session. For shared bindings, use the --persist-to flag to ensure both wrangler dev sessions are using the same persistence directory.

@lrapoport-cf lrapoport-cf added the awaiting reporter response Needs clarification or followup from OP label Dec 4, 2023
@lrapoport-cf
Copy link
Contributor

hi @iustinpericica ! we haven't heard from you in a while, so we’re going to close this issue for now. if this is still a problem, please feel free to open a new issue referencing this one. please be sure to include an updated summary and any additional requested details, followup, or context and we will revisit and investigate further. thanks!

@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Dec 11, 2023
@BerndWessels
Copy link

2024 now, any new official advice how to let multiple workers access the same d1 database? Monorepo?

@flash716
Copy link

flash716 commented Nov 4, 2024

@BerndWessels here's how I did it in a monorepo based on what @mrbbot mentioned, it seems to be working fine though I haven't had a lot of time for testing yet.

I have two apps in my monorepo, one is a Pages app (in web-app directory) and one is a Worker. My Pages app just uses the normal wrangler pages dev command but for the Worker app I have this in my package.json:
"dev": "wrangler dev --persist-to=../web-app/.wrangler/state",

The Worker app now seems to open and read/write from the same DB as the Pages app without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reporter response Needs clarification or followup from OP enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants