Skip to content

docs(cloudflare): dedicated gradual deployments guide - #981

Merged
sam-goodwin merged 8 commits into
mainfrom
claude/cloudflare-gradual-deployments-8f124c
Jul 29, 2026
Merged

sam-goodwin merged 8 commits into
mainfrom
claude/cloudflare-gradual-deployments-8f124c

Conversation

@sam-goodwin

Copy link
Copy Markdown
Member

Add a dedicated guide for Worker versions & gradual rollouts at /cloudflare/compute/gradual-deployments, covering the version prop shipped in #948 plus the surrounding platform workflow from Cloudflare's gradual deployments docs:

  • gradual rollout of a Worker's own deploys (version: { traffic: N }), ramping, promotion, rollback
  • canarying another stage's Worker via version.parent + Worker.ref
  • traffic-free preview versions with stable aliased preview URLs
  • smoke testing with Cloudflare-Workers-Version-Overrides (using the versionId output)
  • version affinity with Cloudflare-Workers-Version-Key
  • runtime verification via the version_metadata binding and version.tag
  • platform limits: two versions per deployment, 100-version window, Durable Object version assignment, version-scoped cache (crossVersionCache)

Also registers the guide in the Compute sidebar and cross-links it from the Workers page.

🤖 Generated with Claude Code

@alchemy-version-bot

alchemy-version-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/dd0d459

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/dd0d459

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/dd0d459

@ericclemmons ericclemmons left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Absolutely no blockers, this is great!

Only clarifying questions that AI can probably fix up.

This is a confusing topic with several gotchas, but this is a very, very good addition for Alchemy and closes a parity gap with wrangler.


const preview = yield* Cloudflare.Worker("Api", {
main: "./src/api.ts",
version: { parent, message: `PR #${process.env.PR_NUMBER}` },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can this be omitted for preview deployments entirely?

The current behavior for preview deployments is to be their own stage, right?

I'm just wanting to understand when I'd do a "normal preview deploy" (with no traffic) vs. a "preview deploy with a parent".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right — a plain preview stage needs no version at all and stays the default workflow. Added a "Preview version or preview stage?" section: a stage is fully independent infrastructure (own script, own copies of every resource), while a preview version rides the parent's script, settings, and version history without adding scripts to the account. Rule of thumb in the guide: stage for infrastructure changes, version for cheap shareable code previews.

- uses: actions/checkout@v4
- run: bun alchemy deploy
env:
API_TRAFFIC: ${{ inputs.traffic }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a fantastic use-case and directly matches the need for health-mediated deployments.

main: "./src/api.ts",
version: {
traffic: 10,
message: "new search index",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Message is optional, right? May be worth calling out what message is used for and how it appears. (This is just what we see in the dashboard, right? Usually it's a commit message, but in this case it's overridden here)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes — message is optional. It is the human-readable note shown next to the version in the Cloudflare dashboard and wrangler versions list (a commit message is the usual choice); tag is its machine-readable sibling. The example now shows both as comments: message: "new search index" and tag: process.env.GITHUB_SHA, and the tag round-trips at runtime through the version metadata binding.

the prop (or set `traffic: 100`) to promote the version to all
traffic.

The very first deploy of a script always goes to 100%, since there is

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very good default of 100%. This is actually a gotcha with wrangler versions upload - you'll get an error unless you deploy 1st!

the majority holder **v1** at 80%. **v2** drops out of routing
entirely.

The abandoned version still exists as an upload, but it receives no

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TIL!

```typescript
const api = yield* Cloudflare.Worker("Api", {
main: "./src/api.ts",
version: { traffic: 1 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This would be 1%, right? Because not setting version would be 100% of the new version. What would 0% do? Only respond to my curl requests (like the preview examples)?

I'm thinking of this example being a manual deploy or HMD for smoke testing.

API_PERCENTAGE=1 alchemy deploy
# outputs versionId

curl -s https://api.example.com/health \
  -H 'Cloudflare-Workers-Version-Overrides: my-api="<versionId>"'
# OK

API_PERCENTAGE=50 alchemy deploy

curl -s https://api.example.com/health \
  -H 'Cloudflare-Workers-Version-Overrides: my-api="<versionId>"'
# UNHEALTHY

alchemy rollback # or whatever the guidance would be. Setting it to 0%?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, exactly 1% — and your flow works as written. traffic: 0 is upload-only: the version never enters the deployment, so an override header cannot reach it (overrides only resolve versions in the current deployment); it is reachable only at its preview URL. traffic: 1 is the smallest override-addressable deployment. The guide now says this inline in the smoke-test snippet, and the abort guidance is: re-deploy the last good ref at the default 100 — the bad version drops out of the deployment entirely.

```

On a zone you control, a
[Transform Rule](https://developers.cloudflare.com/rules/transform/request-header-modification/)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there an Alchemy equivalent of this? For gradual deploys, "sticky deploys" and "version affinity" is a tricky technical topic for a lot of users.

Being able to easily say, "oh yeah, and sticky by cookie/claim, or fallback to sticky IP" would really complete this story.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No sugar yet, but the guide now shows the alchemy-native way: a Cloudflare.Ruleset.Ruleset transform rule in the same Stack that sets Cloudflare-Workers-Version-Key from a session cookie (any stable property works — cookie, claim, tenant id). Caveat included: transform rules only see zone traffic, so bare workers.dev clients send the header themselves. First-class version: { affinity: { cookie: "..." } } sugar that provisions the rule automatically is spun off as a follow-up.

);
```

Set `version.tag` at deploy time (a git SHA is the usual choice) and

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Really good usage of VersionMetadata() 👏

`crossVersionCache: true` to share cached responses across versions
during a rollout.

## Containers roll out by instance, not by request

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

May be worth a similar callback for things like Workflows, logpush, Durable Object migrations, etc.

These need to basically be deployed in a backwards/forwards-compatible way:

  1. Deploy the new service (e.g. Workflow) or new handler in a DO.
  2. Gradually rollout the worker that uses the new call paths while the old version continues calling the current paths.
  3. Once at 100%, you can safely remove the old call paths.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added to "What a version carries": DOs, Workflows, and service bindings sit outside the version, so both versions call them during the rollout — ship those changes expand-and-contract (new path at 100% first, ramp the caller, remove the old path after promotion), and keep KV/D1/DO schema changes compatible with both versions until the rollout completes.

sam-goodwin and others added 2 commits July 28, 2026 22:25
- explain what version.message/tag are for and where they appear
- preview version vs preview stage decision guidance
- clarify traffic:1 vs traffic:0 for smoke tests + abort guidance
- alchemy-native version affinity via Ruleset transform rule
- expand-and-contract recipe for DOs/Workflows/service bindings

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin
sam-goodwin merged commit deeb20e into main Jul 29, 2026
16 checks passed
@sam-goodwin
sam-goodwin deleted the claude/cloudflare-gradual-deployments-8f124c branch July 29, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants