Now
Latest post:AI portal automation: six scheduled tasks and five messages from meNext post:Saturday, 7:30Building:a task schedule that runs the portal: news, articles and refreshes every dayBuilding:rules for automation: one task, one job, one commit as the logBuilding:Famplace, an app that connects parents who live nearby, with a waiting listBuilding:Frinter on the phone: setting up a focus session on one screen
delta240mvt ↗

Staging and production environments: how I release apps on Cloudflare Workers

How my staging and production environments work for two apps: push to main, check, move the branch. And why only the part that changed gets built.

Three rising steps in ink, cyan and yellow, four small modules on the middle one, a gate before the last step, and a small cube travelling up the steps.

A few minutes after three p.m. on Tuesday, November 25, Famplace had its first working staging. One trigger ran a script that deployed eight Workers in three parallel rounds. It worked. I wrote to Claude: “Look at how I build in my other project. The Workers react only to changes. Can’t we do that here?” By evening the trigger was split into four, and I had two apps, Frinter and Famplace, with the same environment layout.

This post is about that layout, because it changed my day: I ship a change and I know where I will see it before it touches real users. If you want to see what Frinter is, there is its story in the portfolio on delta240mvt.com. Here are my numbers and rules.

What does a staging environment look like for my mobile apps?

A staging environment is a second copy of the app where I check a change before production. Mine has its own address, its own database and the add-ons that cost money or collect data switched off.

The path of a change is always the same: local, a push to the main branch (that is staging), a check, and then I move the production branch to the same commit. I do not commit to production. I move the branch to a commit that passed staging, and only when I say “yes.” I took this layout from the Autonomia Kodu platform, where it already worked, and moved it to Frinter and Famplace the same day.

Diagram of three environments: local, staging and production, with a table of differences in database, bot check, visit tracking, session cookie and admin panel.
A diagram from my Frinter environment docs (Famplace has the same layout). The key row is the database: staging has its own Neon project and synthetic data.

What differs, so that staging is a real rehearsal and not a prop? The database: a separate Neon project, and in Famplace only synthetic data. Turnstile and visit tracking run only in production, so on staging I collect nothing that could be mistaken for real traffic. The session cookie has a different domain and prefix on staging, so a staging session cannot log you into production, or the other way around. The admin panel in production sits behind Cloudflare Access, and on staging at a separate address.

In Famplace, for the first hours production built only the landing page, the one with the waiting list. The API, web and admin stayed untouched until I prepared version 2 with separate Workers. That is also part of the layout: a new environment can grow next to the old one, and I decide when traffic moves to it. Only then is a release one move of a branch.

What stays the same matters more than what differs: the same Workers, the same configuration, the same code. A staging that runs something different from production checks nothing.

Why not one big build after every push?

Because the first version worked that way, and it tired me out fast. One script, eight Workers, three rounds: first the ones that depend on nothing (ledger, operations, web, landing), then the API, and last login, admin and jobs. The whole staging took about 2 minutes to build. For a change in the landing page alone, that was 2 minutes and eight deployments for no reason.

In the same conversation I asked something else: “Won’t there be 8 Workers? Do we need that many Hyperdrives? Maybe let’s limit it to one or two to start, because I will have Frinter on staging too.” I was thinking about cost and clutter. Two apps on one Cloudflare account quickly become a dozen services, and each needs watching. So the first decision was to do no more than needed, and the second was to build only what changed.

In Frinter this split already existed, because every Worker has its own Workers Builds trigger with the app directory as its root and a list of watched paths. In Famplace I did the same thing, only coarser: four triggers instead of eight.

Four columns: backend, landing, web and admin, each with the list of paths its trigger watches.
Four triggers on Famplace staging (from the project README). The backend deploys the API, identity, jobs, ledger and operations from one codebase, in rounds. The rest have one area each.

The rule is simple. Each trigger watches its own directory, the shared contracts and the packages it really imports. A change only in the README, in docs/, in marketing material or in tests starts no build. A change in shared files, such as the lockfile or the deploy script, starts all four. The whole job is keeping the path list in line with what the code actually imports, because if an entry is missing, a change in a package will not start a build and I will see it only after the next one.

How many seconds does that save?

Numbers from Frinter, because that is where I have them written down:

What Before After
Installing dependencies in a build about 60 s about 10 s
Building the web apps in CI with a package prebuild and file compression without both, Cloudflare compresses on its own
Moving web and admin from Pages to Workers — about 3 s per address

Installation dropped from about a minute to about ten seconds, because each trigger installs only its own workspace and the packages that workspace declares, with a dependency cache. The price: every Worker must list in its package.json everything it imports, because a clean checkout has nothing that would be installed “by accident.” Two commits that evening fixed exactly that: missing package declarations in two Workers.

Triggers that match one push start at the same time, so the whole staging builds as long as its slowest Worker, not the sum of all. On my account at most 6 builds run at once, and the seventh waits for a free slot. That is a good reason to keep the path lists narrow.

What do I do when a change touches several areas?

I make changes across areas additive: first the new API route or field, and its use in the web app or admin in the next push. The areas deploy independently and in no particular order, so during a deployment the old web app has to keep working with the new API. Database migrations only add columns with a default value, for the same reason. I do not reset staging.

It sounds like bureaucracy, but in practice it is one question before every commit: will the old code survive a moment with the new? If yes, I push. If not, I split the change into two pushes. A permanent staging is what turned this rule from good advice into a habit, because I see right away when I broke it.

I left two things out of this flow on purpose. The Frinter blog is deployed by an automation straight to the site, separately from the app, and it refuses to work on the production branch, because a push to that branch deploys the app. And Famplace production version 2 has Workers with a -production ending, separate from the old ones, so the old ones are safe until I say “switch.”

Why did I switch off two services along the way?

Because staging forces an inventory. When I connected Frinter to the new layout, I saw two services in the metrics with zero requests in the period I checked: one for surveys, quizzes, chat and analytics in the admin panel, the other for community features, practically dead. The code still used them, but nobody was using the features. I removed both along with everything that led to them. Fewer Workers means fewer deployments and fewer things to watch.

The same day I did a “big cleanup” of the whole Cloudflare account. I asked for a list of projects, Workers, databases and buckets, marking which have a domain and which are old. We went through it project by project, and I said what to delete. An old Pages project went, followed by empty KV spaces and buckets nothing was using. What stayed are the things I know the purpose of. A tidy account is a condition for staging to be readable at all: when there are a hundred services, I do not know which belongs to which.

I described the setup of Cloudflare itself, on which all this stands, earlier in the post on the free plan as security for a SaaS. This one is about something different: the path of a change, not the shield.

What I take from this

Before you deploy anything “for a trial,” answer one question: is what I am checking the same thing that will go to production? If staging has different code, different Workers or the same database as production, it is not staging, just a second place for bugs.

The second thing is narrow triggers. Each area has its own list of paths, and the README and tests wake nobody. I gained not so much time (though a minute from installation too) as peace of mind: a push to documentation touches nothing that could break.

And the third, most expensive lesson: the first version is usually too big. Eight Workers in one script worked, but only because I was not looking at what it cost. I asked “do we need this many?” only after the first success. Today I ask it before. I asked a similar question about unnecessary work with the scroll animations on iPhone: the fastest code is the code you do not run, and the fastest build is the one that does not start.

Want to build something like this yourself?

I work with people 1:1 under the delta240mvt brand. On your project, from the first step.

See the offer ↗