Worker Version Deployment, Gradual Rollout, Rollback, and Affinity
How Cloudflare Workers versions and deployments work: upload vs deploy, traffic splits, rollbacks, affinity, and limits.
This page summarises Cloudflare’s documentation on Workers versions and deployments: what a version stores, how a deployment routes traffic, how to upload without going live, how gradual deployments split traffic, how rollbacks work, and how version affinity and version overrides help you test and avoid broken rollouts.
Versions and deployments: what changes when you deploy
Section titled “Versions and deployments: what changes when you deploy”A version is a snapshot of your Worker at one point in time: bundled code, static assets, bindings, and compatibility settings. Each version has a unique ID and metadata about who created it and when.
Every time you change your Worker’s code or configuration, Workers creates a version. A deployment determines which version(s) are actively serving traffic.
— Cloudflare, Versions & deployments
A deployment decides which version(s) serve traffic. It can point at one version (100% of traffic) or two versions with a percentage split during a gradual rollout.
A version captures the complete state of your Worker at a point in time: its bundled code, static assets, bindings, and compatibility settings.
— Cloudflare, Versions & deployments
Default wrangler deploy vs separating upload and deploy
Section titled “Default wrangler deploy vs separating upload and deploy”By default, upload and go-live are one step:
By default, a new version is created and immediately deployed to 100% of traffic when you use any of the following:
wrangler deploy, Workers Builds, The Workers Script Upload API— Cloudflare, Deployment management
You can decouple them so you choose when traffic moves:
You can separate these steps so that uploading a version and deploying it are independent actions. This lets you control exactly when a new version goes live.
— Cloudflare, Deployment management
| Goal | Typical command or UI action |
|---|---|
| Create a version without serving it | wrangler versions upload or dashboard Deploy menu → Save (deployment management) |
| Route traffic to uploaded version(s) | wrangler versions deploy or dashboard Promote deployment |
| One-step production release | wrangler deploy or Workers Builds on production branch |
Versions uploaded via wrangler versions upload must use ES modules format; service worker syntax is not supported for those uploads (deployment management).
Gradual deployments: split traffic between two Worker versions
Section titled “Gradual deployments: split traffic between two Worker versions”Gradual deployments send only part of production traffic to a new version while the rest stays on the previous one—useful for monitoring errors before a full cutover or rolling back quickly if something fails.
Gradual deployments let you incrementally deploy new versions of your Worker by splitting traffic across versions. Instead of shifting all traffic to a new version at once, you can route a percentage of requests to the new version while the rest continue to be handled by the previous version.
— Cloudflare, Gradual deployments
How to start a gradual deployment with Wrangler
Section titled “How to start a gradual deployment with Wrangler”-
Upload a new version (not live yet):
npx wrangler versions upload -
Create a split deployment and set percentages interactively:
npx wrangler versions deployNon-interactive example from the Wrangler
versions deployreference:wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2@90% -y -
When satisfied, run
wrangler versions deployagain and set the new version to 100%.
In the dashboard: edit code → Save (new version) → Deployments → Promote deployment to configure the split (gradual deployments).
Workers currently support at most two versions in one active deployment (version overrides). You can only create a gradual deployment using one of the last 100 uploaded versions (gradual deployments, deployment management).
Version skew: why gradual rollout can break pages and microservices
Section titled “Version skew: why gradual rollout can break pages and microservices”When two versions run at once, the same user or downstream call chain may hit different code:
Because gradual deployments mean multiple versions of your Worker serve traffic simultaneously, clients and services can end up interacting with more than one version in ways that produce errors or inconsistent behavior. This is called version skew.
— Cloudflare, Gradual deployments
By default, each request is routed independently, so consecutive loads from one browser can land on different versions (gradual deployments). With service bindings, an upstream Worker on a new version might call a downstream Worker still on an old API (gradual deployments). Use version overrides on subrequests when you need to pin a downstream Worker during debugging.
Version affinity: pin users to one version during a split
Section titled “Version affinity: pin users to one version during a split”Version affinity routes all requests that share a stable key to the same Worker version for the duration of the gradual deployment—critical when HTML and hashed asset files must match.
Version affinity solves this by deterministically assigning users to a version based on a stable identifier, so they consistently hit the same version across page loads and subrequests for the duration of the gradual deployment.
— Cloudflare, Version affinity
Set the Cloudflare-Workers-Version-Key header on requests (from the Internet or on service-binding subrequests). The platform hashes the key and maps it to a version using your configured percentages—you do not pick the mapping manually (version affinity).
Common approaches from version affinity:
- Logged-in apps: Transform Rule sets
Cloudflare-Workers-Version-Keyfrom a cookie such asuser_id. - Anonymous traffic: use client IP (
ip.src) or set a long-lived cookie from the Worker, then mirror it intoCloudflare-Workers-Version-Keyvia a Transform Rule.
Verify with repeated requests using the same header:
curl -s https://example.com -H 'Cloudflare-Workers-Version-Key: test-user-123'curl -s https://example.com -H 'Cloudflare-Workers-Version-Key: test-user-123'Include the version ID in responses during tests using the version metadata binding (CF_VERSION_METADATA).
Version overrides and Version URLs: test before you raise traffic
Section titled “Version overrides and Version URLs: test before you raise traffic”Version overrides (smoke tests and downstream pinning)
Section titled “Version overrides (smoke tests and downstream pinning)”Version overrides force a single request to a specific version ID that is already part of the current deployment, including a version at 0% traffic—typical pattern for production smoke tests (version overrides).
curl -s https://example.com -H 'Cloudflare-Workers-Version-Overrides: my-worker-name="dc8dcd28-271b-4367-9840-6c244f84cb40"'Overrides apply only to fetch()-based service binding calls, not RPC on bindings (version overrides). If the header is invalid or the version is not in the active deployment yet, routing falls back to normal percentages (version overrides).
Gradual deployments with mTLS bindings support this workflow (Workers platform changelog); changelog entries from 2024-07-01 describe version overrides for targeting a specific version during gradual deployments.
Version URLs (isolated preview of one upload)
Section titled “Version URLs (isolated preview of one upload)”When Version URLs are enabled, wrangler versions upload can return a public URL for that version without changing production traffic. Version URLs are not generated for Workers that implement Durable Objects (including Containers and Sandbox Workers) or Workers for Platforms user Workers (version URLs). Protect public version URLs with Cloudflare Access if needed.
For container-backed Workers, non-production Workers Builds often use wrangler versions upload, which updates Worker code but may not publish images or roll out instances; production should use wrangler deploy so package and image stay in sync (Deploy Containers).
Rollbacks: revert production to an older Worker version
Section titled “Rollbacks: revert production to an older Worker version”A rollback creates a new deployment that sends 100% of traffic to the version you pick—immediately across routes and domains (Rollbacks).
You can roll back to a previously deployed version of your Worker using Wrangler or the Cloudflare dashboard. Rolling back to a previous version of your Worker will immediately create a new deployment with the version specified and become the active deployment across all your deployed routes and domains.
— Cloudflare, Rollbacks
| Situation | What rollback does |
|---|---|
| Single-version deployment | Replaces current version with selected version at 100% |
| Split (gradual) deployment | Replaces both versions with one selected version at 100% (Rollbacks) |
Wrangler: wrangler rollback or wrangler rollback <VERSION_ID> (Wrangler rollback, agents configuration). Dashboard: Workers & Pages → your Worker → Deployments → ⋮ on the target version → Rollback (Rollbacks).
You can roll back only among the 100 most recently published versions (Rollbacks, changelog). That same window applies when promoting versions or splitting traffic among recent uploads.
Cloudflare Pages (static JAMstack projects) uses a separate model: production can roll back to any successful production build, not preview deployments (Pages rollbacks).
Durable Objects, cache, and Workers for Platforms limits
Section titled “Durable Objects, cache, and Workers for Platforms limits”Durable Objects and gradual rollout
Section titled “Durable Objects and gradual rollout”Only one Worker version of each Durable Object runs at a time. On a new gradual deployment, each object instance is assigned a version from your percentages and keeps it until the next deployment (With Durable Objects). Code updates propagate eventually; a new Worker version can briefly talk to an object still on older code—plan forward and backward compatible APIs (Known issues, With Durable Objects).
Pending Durable Object migrations may require wrangler deploy rather than upload-only flows (Gradual deployments).
Cache still serving an old Worker after deploy
Section titled “Cache still serving an old Worker after deploy”Normally the Worker version is part of the cache key. If cache.cross_version_cache is enabled, purge after deploy or use version-tagged purge on rollback (Worker cache debugging).
Workers for Platforms
Section titled “Workers for Platforms”Gradual Deployments is not supported for user Workers in Workers for Platforms; those deploy 100% at once (limits).
Common mistakes
Section titled “Common mistakes”- Gradual rollout without affinity on apps with content-hashed static files → HTML from version A and
.jsfrom version B → 404s (version affinity). - Assuming rollback restores KV/D1/DO data → only Worker code/configuration in the version returns; storage evolves independently (Versions & deployments).
- Using
wrangler versions uploadon production Containers Workers to test a new image on the same Worker that serves users → can roll container instances users already hit; use staging Worker/environment and fullwrangler deploy(Deploy Containers). - Editing Worker B without a new version on Worker A when only service-binding configuration on A changes—connected Worker code edits do not automatically version the other Worker (deployment management).
- Expecting version overrides on RPC service bindings → overrides work on
fetch()bindings only (version overrides).
Optional metadata on upload: workers/message, workers/tag, and workers/alias via the Version Upload API metadata or Wrangler flags --message, --tag, --preview-alias (Wrangler versions upload).
How to check this on your site
Section titled “How to check this on your site”-
In the Cloudflare dashboard, open Workers & Pages → your Worker → Deployments and confirm the Active deployment lists the expected version ID(s) and percentages.
-
Run
wrangler deployments list(see Wrangler Workers commands) and match version IDs to production. -
During a gradual rollout, send repeated requests with the same
Cloudflare-Workers-Version-Keyand confirm consistent behavior; use the version metadata binding or Observability/Logpush as described in version overrides. -
After rollback or deploy, hit production URLs and watch analytics for error spikes; if cache looks stale with
cross_version_cache, follow cache debugging. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.