Repository navigation
Add support for versions in service bindings #13282
Replies: 13 comments
|
@dario-piotrowicz here the feature request, about the improvement we talked about privately. Let me know if I can improve the text in any way? |
|
Thanks @alexanderniebuhr, looks perfect, I'll share it with the team 😄👍 |
|
@alexanderniebuhr Hi! I'm a Product Manager at Cloudflare, and wanted to follow up about this. We are currently researching / speccing out how to solve this overall problem of specifying an arbitrary version to route to. Once we have something more formal to share, we'd definitely like your feedback on the approach -- I'll chat with some people to see what timing we're considering, and follow up. |
|
do version overrides work here for calls between service bindings? Ex passing this header in |
|
@irvinebroque I’ve experimented briefly with version overrides, but I haven’t been able to confirm whether they apply to service bindings between two Workers or not. I know they work for client-initiated fetch requests, but I suspect they don’t for Worker-to-Worker bindings. Could someone familiar with them clarify whether version overrides are supported for service bindings? Also where would you define the version id for the override, to support full stack pr previews. We can't hard code it, so it needs to be a dynamic variable and it needs to be defined in a way where it only affects the current pr and not affects other deployments. I was thinking about env variables, but I don't think I can set them per version without affecting other deployments, can I? |
|
@irvinebroque I just validated that it doesn't work with
|
|
In the meantime I was trying to use the url as an build time variable and have a different build for each PR, which inlines the versions url as string
|
|
@irvinebroque the version overrides work only for gradual deployments and only to specify one of the two active versions. I'm not very keen on allowing specific versions to be specified at deployment time via wrangler.toml. I think this is too error prone for most users to handle correctly. Instead what I'd like to see is atomically deployed and version pinned multi-worker applications. If we had this concept in the platform, creating fullstack previews would just work using the existing version preview mechanism. |
|
If dynamic dispatch was a thing in Workers (not just Workers for Platforms) — and extended to be able to get a specific version of a Worker, then you could do something like this? export default {
async fetch(request, env) {
const worker = env.dispatcher.get({ name: "some-name", version: "some-id" });
return await worker.fetch(request);
},
};(assume by default, all Workers on your account are part of a namespace, so that they can be dynamically dispatched to) ...seems like that could help here? Without having to specify the version ID in the configuration of a service binding, or even necessarily use service bindings at all? |
|
@irvinebroque That feels like it would still add a lot of boilerplate to multi-worker preview usecases, and it would make deployment in that case fairly hard. You'd have to have all the versions as environment variables, and deploy the service graph from the leaf nodes inwards, setting the version ID variables as you knew them. |
|
Oh yeah I forgot to add the other piece that we need (tagged you in internal doc) Lot of bikeshedding to do on API design and naming ( ...then in dynamic dispatch: export default {
async fetch(request, env) {
// figure out how the request should be served — should we serve the canary version that we just released for employees, since this incoming request is from an employee? Ex:
const worker = env.dispatcher.get({ name: "some-name", group: "employee" });
return await worker.fetch(request);
},
};All for other ideas here, don't think we have it right or nailed down. |
|
@irvinebroque I think we still talk about different things, looking at your examples, you have |
|
I had created an issue: #16722 for versioned RPC bindings. I just wanted to raise this here for visibility. I hope this feature continues to move forward! |
Uh oh!
There was an error while loading. Please reload this page.
Describe the solution
Summary
Currently, service bindings always point to the latest deployed version of a Worker. This prevents creating an isolated, full-stack preview environment for pull requests, where both frontend and backend Workers can be tested together against their respective preview versions.
Background
wrangler versions upload, which returns a unique version ID.Motivation
When developing changes that span multiple Workers (e.g., frontend and backend), it is crucial to:
wrangler versions upload)Without this capability, teams cannot spin up an isolated, full-stack preview environment for every PR.
Proposal
wrangler.toml/wrangler.jsonc(and/or corresponding CLI flag) to specify a target version ID for service bindings:{ "services": [ { "binding": "<BINDING_NAME>", "service": "<WORKER_NAME>", "version": "<VERSION_ID>" } ] }Behavior:
version_id(or@version_idon the CLI) is provided, the binding resolves to that specific preview version.Alternatives
Separate preview namespace per PR: Create isolated namespaces or services for each PR.
Ephemeral subdomain routing: Use runtime overrides (e.g., originating subdomain) to route calls to a matching PR version.
Benefits
All reactions