Multi Workers development
When building complex applications, you may need to run multiple Workers during development. This guide covers the different approaches for running multiple Workers locally and when to use each approach.
You can run multiple Workers in a single dev session by passing multiple configuration files to your dev server.
-
Create separate configuration files for each Worker:
Primary Worker
{"name": "app-worker","main": "./src/index.ts","services": [{"binding": "API","service": "api-worker"}]}name = "app-worker"main = "./src/index.ts"[[services]]binding = "API"service = "api-worker"Auxiliary Worker
{"name": "api-worker","main": "./src/index.ts"}name = "api-worker"main = "./src/index.ts" -
Start a dev session:
Using Wrangler
Terminal window npx wrangler dev -c wrangler.jsonc -c ../api/wrangler.jsoncTerminal window yarn wrangler dev -c wrangler.jsonc -c ../api/wrangler.jsoncTerminal window pnpm wrangler dev -c wrangler.jsonc -c ../api/wrangler.jsoncThe first config is treated as the primary Worker, exposed at
http://localhost:8787
. Additional configs run as auxiliary Workers, available via service bindings or tail consumers from the primary Worker.Using the Vite plugin
Configure
auxiliaryWorkers
in your Vite configuration:vite.config.js import { defineConfig } from "vite";import { cloudflare } from "@cloudflare/vite-plugin";export default defineConfig({plugins: [cloudflare({configPath: "./wrangler.jsonc",auxiliaryWorkers: [{configPath: "../api/wrangler.jsonc",},],}),],});Then run:
Terminal window npx vite devTerminal window yarn vite devTerminal window pnpm vite dev
Use this approach when:
- 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
You can also run each Worker in a separate dev session, each with its own terminal and configuration.
# Terminal 1wrangler dev
# Terminal 2wrangler dev
These Workers run in different dev sessions but can still communicate with each other via service bindings or tail consumers regardless they are started with wrangler dev
or vite dev
.
Use this approach when:
- Each Worker uses a different build configuration
- Different teams maintain the Workers
- A Worker only occasionally accesses another, and you prefer the flexibility to run them separately
While this setup offers flexibility, there are some limitations to be aware of when using bindings across Workers running in separate dev sessions:
Bindings | Wrangler (single config) | Wrangler (multi config) | Vite (no auxiliaryWorkers) | Vite (with auxiliaryWorkers) |
---|---|---|---|---|
Service Bindings | โ | ๐ | โ | โ |
Durable Objects | โ ๏ธ | โ | โ | โ |
Tail Consumers | โ | ๐ | โ | โ |
โ = Full support. โ ๏ธ = Fetch only. RPC is not supported. ๐ = No support yet. Coming soon. โ = Not supported.
You can also combine both approaches โ for example, run a group of Workers together through vite dev
using auxiliaryWorkers
, while running another Worker separately with wrangler dev
.
# Terminal 1vite dev
# Terminal 2wrangler dev
This allows you to keep tightly coupled Workers in a single dev session, while treating independent or shared Workers as separate sessions.
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
- Your project structure benefits from the flexibility of both approaches
The same limitations for bindings apply when Workers are run across multiple dev sessions. Refer to the table above for what's supported when Workers aren't started in the same dev command.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark