How to handle KV / Queue bindings for branch-based preview deployments?
🖥️D1🪣R2🔑KVWorkers🌍Durable Objects
Hey everyone
I’m working on branch-based preview environments for a Workers project and trying to figure out the best way to handle bindings like KV, Queues, Hyperdrive, etc.
Our workflow currently looks like this:
*
dev
dev
→
dev-feature-branch
dev-feature-branch
* When a feature branch is created, we clone our Postgres database for that branch. * For Postgres this works fine because we can just pass a DATABASE_URL(so we don’t need Hyperdrive).
The challenge is with Workers bindings, since they’re defined statically in
* Deploy a preview Worker for a branch * During that deployment, preview resources get created automatically(KV namespace, Queue, etc.) * The preview Worker uses those resources * When the preview is deleted, merged, or promoted, those preview resources get cleaned up automatically
Basically something like ephemeral bindings/resources tied to preview deployments.
Right now it seems the only options are:
* Share preview resources and prefix keys by branch * Or create resources via CI and update
wrangler.jsonc
wrangler.jsonc
dynamically
Is there a recommended pattern for this with Workers today? Or any plans for ephemeral preview resources similar to how preview deployments work in other platforms?